SQL: How to use a column that was just added

Posted by sbenderli on Stack Overflow See other posts from Stack Overflow or by sbenderli
Published on 2010-06-10T14:00:06Z Indexed on 2010/06/10 14:02 UTC
Read the original article Hit count: 145

Filed under:
|

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 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


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 

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

© Stack Overflow or respective owner

Related posts about sql

Related posts about columns