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

  • Home
  • SEARCH
  • 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 6155399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:25:46+00:00 2026-05-23T20:25:46+00:00

When executing the following script, I get the error: Msg 207, Level 16, State

  • 0

When executing the following script, I get the error:

Msg 207, Level 16, State 1, Line 15 Invalid column name ‘b’.

Anyone can explain it please? Thanks.

DROP TABLE ttt;
CREATE TABLE ttt(a nvarchar)

IF NOT EXISTS ( SELECT  *
                FROM    sys.columns
                WHERE   object_id = OBJECT_ID('dbo.ttt')
                        AND name = 'b' )
    AND EXISTS ( SELECT *
                 FROM   sys.columns
                 WHERE  object_id = OBJECT_ID('dbo.ttt')
                        AND name = 'a' ) 
    BEGIN

        ALTER TABLE [dbo].ttt ADD b NVARCHAR

        UPDATE  [dbo].ttt
        SET     b = a

        ALTER TABLE [dbo].ttt DROP COLUMN a
    END
  • 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-23T20:25:46+00:00Added an answer on May 23, 2026 at 8:25 pm

    It’s trying to compile all of these statements before it executes the 1st:

     ALTER TABLE [dbo].ttt ADD b NVARCHAR
    
        UPDATE  [dbo].ttt
        SET     b = a
    
        ALTER TABLE [dbo].ttt DROP COLUMN a
    

    (In fact, it tries to compile the entire batch, not just these statements, but the point still stands – at the point it’s trying to compile the UPDATE, the column does not exist)

    When it’s trying to compile the UPDATE statement, it consults the table metadata and correctly finds that the column doesn’t exist.

    Try EXECing the update statement.

        EXEC('UPDATE  [dbo].ttt
        SET     b = a');
    

    And also, what Oded says about you probably wanting to specify a size for the column (otherwise, it defaults to the most pointless datatype ever – an nvarchar(1))


    This script definitely runs without errors:

    CREATE TABLE ttt(a nvarchar)
    
    IF NOT EXISTS ( SELECT  *
                    FROM    sys.columns
                    WHERE   object_id = OBJECT_ID('dbo.ttt')
                            AND name = 'b' )
        AND EXISTS ( SELECT *
                     FROM   sys.columns
                     WHERE  object_id = OBJECT_ID('dbo.ttt')
                            AND name = 'a' ) 
        BEGIN
    
            ALTER TABLE [dbo].ttt ADD b NVARCHAR
    
            EXEC('UPDATE  [dbo].ttt
            SET     b = a');
    
            ALTER TABLE [dbo].ttt DROP COLUMN a
        END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to make my table can filtering in each column. i get client
When I run my script I receive the following error before processing all rows
I get the following error: Uncaught Syntax error, unrecognized expression: [src$==copyright.gif] k.errorjquery_1_6_2_min.js:17 k.filterjquery_1_6_2_min.js:17 kjquery_1_6_2_min.js:17
When executing the following (complete) SQL query on Microsoft SQL Server 2000: SELECT B.ARTIFACTTNS,
I'm executing the following query: Select guiPolygonID, dbo.fn_Yval(p1X, p1Y, p2X, p2Y, 4.003318) From [vPolygonSegments]
Imagine the following A type T has a field Company. When executing the following
I just tried to create my first plpgsql function. When executing the script, I
Am trying the following php script which finds out the maximum between 2 numbers,
I am trying to run the following commands as part of an MSBuild script:
I am using VSTS 2008 + C# + .Net 2.0. When executing the following

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.