0
我有一个包含5列的临时表。我从现有的表中获得四列,所以使用select语句插入,这工作正常。带有参数的exec中的更新语句 - 无效的列错误
但是,没有填充的列我需要它是一个基本上是参数值的字符串。我试图在插入后运行一个简单的更新语句,并且我得到一个错误无效的列。
部分代码如下。 此时参数已经填充了相应的值。
exec ('CREATE TABLE ' + @temp_table_runID + '(
[DBName] [nvarchar] (100),
[RunID] [bigint] ,
[OrchID] [bigint] ,
[OrchVersion] [bigint] ,
[TimeStamp] [bigint]
) ON [PRIMARY]')
--exec('select * from ' + @temp_table_runID)
-- Insert from the primary database
exec(' INSERT INTO ' + @temp_table_runID + '
(
[RunID],
[OrchID] ,
[OrchVersion] ,
[TimeStamp]
)
SELECT R.RunID, R.OrchID, R.OrchVersion, R.TimeStamp
FROM ' + @primaryDB + '.dbo.Run R, ' + @primaryDB + '.dbo.SeriesVariables S
WHERE S.SeriesVariables_Value = ''SplitSystemTest2''
AND S.Series_ID = R.RunID order by R.Timestamp ASC')
-- The below statement does not work and get an error invalid column name 'reportingdb_24feb14'. The value of the @primaryDB = reportingdb_24feb14.
-- update the table with database name
exec('update ' + @temp_table_runID + ' SET DBName = ' + @primaryDB)
任何帮助,非常感谢。谢谢。
这是很好的答案。有用。谢谢。 – Abe
我只是想知道有没有单独的更新声明。我可以在插入语句中插入DBName值。谢谢。 – Abe
我只是选择'''+ @primaryDB +'''...等等等等,如上所示,它的作品就像一个魅力。不需要单独的更新语句。干杯所有。 – Abe