Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 868557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:09:36+00:00 2026-05-15T10:09:36+00:00

I am trying to add 2 columns and then I would like to set

  • 0

I am trying to add 2 columns and then I would like to set some values to them but I get a compile-error saying the column does not exist. I am using the following script:

IF @LogProcessed = 0
Begin

IF NOT EXISTS (select column_name from INFORMATION_SCHEMA.columns where table_name = 'SYSTM_FRM' and column_name = 'SF_Ip_TXT')
ALTER TABLE SYSTM_FRM add SF_Ip_TXT NVARCHAR(20)

IF NOT EXISTS (select column_name from INFORMATION_SCHEMA.columns where table_name = 'SYSTM_FRM' and column_name = 'SF_Port_NUM')
ALTER TABLE SYSTM_FRM add SF_Port_NUM int


IF  (EXISTS (select column_name from INFORMATION_SCHEMA.columns where table_name = 'FRM' and column_name = 'FRM_Ip_TXT') AND
    EXISTS (select column_name from INFORMATION_SCHEMA.columns where table_name = 'FRM' and column_name = 'FRM_Ip_TXT'))
begin
Update dbo.SYSTM_FRM
SET     dbo.SYSTM_FRM.SF_Ip_TXT = dbo.FRM.FRM_Ip_TXT,
        dbo.SYSTM_FRM.SF_Port_NUM = dbo.FRM.FRM_Port_NUM

FROM dbo.FRM INNER JOIN dbo.SYSTM_FRM ON dbo.FRM.FRM_RCRD_NUM = dbo.SYSTM_FRM.SF_FrameRecord_NUM          

ALTER TABLE FRM DROP COLUMN FRM_Ip_TXT
ALTER TABLE FRM DROP COLUMN FRM_Port_NUM  
  end


Update [Update_Log]
Set Update_Log_Processed = 1
Where [Update_Log_Version] = '00001'

end

Is there any way to use a column that I am adding in the same script?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:09:36+00:00Added an answer on May 15, 2026 at 10:09 am

    you cannot save it in a proc like that

    example

    create table TestAdd2 (id int)
    go
    

    You cannot create this procedure

    create proc prTest as
    
    insert TestAdd2 values (1)
    
    exec ('ALTER TABLE TestAdd2 add SF_Port_NUM int')
    
    update TestAdd2 set id = 1,SF_Port_NUM = 2
    
    select * from TestAdd2
    
    GO
    

    You get this error
    Msg 207, Level 16, State 1, Procedure prTest, Line 7
    Invalid column name 'SF_Port_NUM'.

    This is because at parse time the column does not exist

    However if you use dynamic SQL for the update you are good to go

    create proc prTest2 as
    
    insert TestAdd2 values (1)
    
    exec ('ALTER TABLE TestAdd2 add SF_Port_NUM int')
    
    exec ('update TestAdd2 set id = 1,SF_Port_NUM = 2')
    
    select * from TestAdd2
    
    GO
    

    in your case your update statement would be

    exec('Update dbo.SYSTM_FRM
    SET     dbo.SYSTM_FRM.SF_Ip_TXT = dbo.FRM.FRM_Ip_TXT,
            dbo.SYSTM_FRM.SF_Port_NUM = dbo.FRM.FRM_Port_NUM
    FROM dbo.FRM INNER JOIN dbo.SYSTM_FRM 
    ON dbo.FRM.FRM_RCRD_NUM = dbo.SYSTM_FRM.SF_FrameRecord_NUM')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add more values to my row, but all the columns
I'm just trying to add 2 columns to customer table alter table CUSTOMER ADD
Trying to add a dynamic class value to one of my columns in CGridView:
I am trying to add my data into multiple columns ListBox, I did it
I am trying to add a new column into an SQLiteDatabase but every time
Basically i would like to add a new column in a table entitled product
Hi every One I am trying to add column in Mysql. My Sql Query
I am trying to add bootstrap drop down button in a column of jqGrid
I'm trying to add a custom filter to my RadGrid. I have a column,
I'm trying add data triggers to the default combobox style so each text item

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.