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 using joomla. I don't know if I'm using the
First time posting on here, so I hope I do this correctly, however I
first time SO user :) I know that I can format a number like
This is my first time attempting to call an ASP.NET page method from jQuery.
This is my first time with Web services. I have to develop web services
This is my first post in any forum so please bear with me. I
This is my first time using splint (from Ubuntu repositories) and I immediately got
The first time I load the website in the production web server, it start
The first time I try to open a particular form many of the controls
Long time listener, first time caller. I'm a full time SE during the day

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.