【发布时间】:2013-10-30 22:43:12
【问题描述】:
我在 SQL Server 2008 中的存储过程中有以下内容
declare @sql as varchar(max)
set @sql='select col1,col2 from remote server'
我想做的是
insert into mytable(col1,col2)
exec(@sql)
Where not exists
(select * from mytable where col1=?,col2=?)
这不起作用。有没有办法解决这个问题。我的动态 sql 将保持原样,因为这是使用 openquery 从某个远程服务器获取数据。所以我没有解决方案,只能在插入时调用exec(@sql)。也不知道如何用我应该替换“?”在 Where NOT Exists 子句中,因为数据来自动态 SQL。
【问题讨论】:
-
如果您认为以前的问题有帮助(或者它们是正确的),您应该接受它们的答案。
标签: sql-server-2008 tsql dynamic sql-insert not-exists