简体   繁体   English

请告诉我为什么此代码引发错误

[英]Please tell me why this code is throwing an error

I can not for the life of me figure out what is wrong with this code: 我一生无法弄清楚这段代码出了什么问题:

IF NOT EXISTS(SELECT * FROM sys.columns WHERE name = 'Report_Date' 
                       AND object_id = OBJECT_ID('TempTable3'))
    ALTER TABLE TempTable3 ADD Report_Date datetime

--Set "ReportDate" field to the date the data was extracted less one.
UPDATE TempTable3
SET Report_Date = '20100815'

I keep getting this error: 我不断收到此错误:

"Msg 207, Level 16, State 1, Line 51
Invalid column name 'Report_Date'."

Put a GO after alter table 将GO放在alter table之后

ALTER TABLE TempTable3 ADD Report_Date datetime
GO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM