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 4240060
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:06:58+00:00 2026-05-21T03:06:58+00:00

First time posting, please let me know if this question has already been answered!

  • 0

First time posting, please let me know if this question has already been answered! I tried searching around, but couldn’t find anything.

In my stored procedure, I select into a temp table while I do some modifying (Ive dumbed it down to the basic issue).

SELECT 'a' AS ColA, 'b' AS ColB INTO #tmp

ALTER TABLE #tmp 
    ADD ColC char(5) NULL, 
        ColD char(5) NULL, 
        ColE char(5) NULL

UPDATE #tmp
SET ColC = 'c',
    ColD = 'd',
    ColE = 'e'
FROM #tmp

SELECT * FROM #tmp

In Query Analyzer, If you highlight & run them separately, in order, I get the desired output.

ColA ColB ColC  ColD  ColE
---- ---- ----- ----- -----
a    b    c     d     e    

However, when I run them all together, I get the following error:

(1 row(s) affected)
Msg 207, Level 16, State 1, Line 10
Invalid column name 'colC'.

It looks like the ALTER TABLE statement is being skipped over? I inserted GO statements after each command, and the code worked in query analyzer. However, I cannot figure out how to replicate this in a stored procedure. (Is there a “GO” equivalent for s-procs?)

Any help is greatly appreciated!

  • 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-21T03:06:59+00:00Added an answer on May 21, 2026 at 3:06 am

    GO is not part of T-SQL, it’s a batch separator supported by a number of SQL Server tools.

    You can generally do the ALTER TABLE with an EXEC, but if your problem requiring an ALTER immediately after a create was how to get dummy columns, then your specific example can simply be done:

    SELECT 'a' AS ColA
        ,'b' AS ColB
        ,CAST(NULL AS char(5)) AS ColC
        ,CAST(NULL AS char(5)) AS ColD
        ,CAST(NULL AS char(5)) AS ColE
    INTO #tmp
    
    UPDATE #tmp
    SET ColC = 'c',
        ColD = 'd',
        ColE = 'e'
    FROM #tmp
    
    SELECT * FROM #tmp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time posting a question here, it has been a valuable
This is the first time I am posting a question on stackoverflow, so please
this is my first time posting here, I have a question which I have
That's my first time posting on stackoverflow. I've been finding usefull answers on this
this is my first time posting here, but I didn't know where else to
First time posting a question on StackOverflow, so please go easy on me :)
this is my first time on posting so if I have done anything please
This is my first time posting on Stackoverflow, but I've been reading through many
this is my first time posting a question here - I've searched for ones
first time posting here, but god know's I use this site to search for

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.