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

HI, I get the following error on executing a script: [Thu Jul 15 17:32:02
while executing the following query, i get an error that there's an error in
The following PL/SQL will not execute and simply returns 'Invalid Argument' as an error.
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
I'd like to get access to the current executing Controller so I can offload
When executing the following (complete) SQL query on Microsoft SQL Server 2000: SELECT B.ARTIFACTTNS,
Try executing the following in JavaScript: parseInt('01'); //equals 1 parseInt('02'); //equals 2 parseInt('03'); //equals
I'm executing the following query: Select guiPolygonID, dbo.fn_Yval(p1X, p1Y, p2X, p2Y, 4.003318) From [vPolygonSegments]
I've tried executing the following: #!C:\cygwin\bin\bash.exe ls ${WORKSPACE} But that doesn't find ls (even

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.