动态参数--必须声明标量变量
之前没有使用动态参数,现在想搞成使用动态参数
insert into @OrderTable select * from dbo.Order_Basicinfo as a where exists (select TID from @table as b where a.TID=b.TID);
select * from @OrderTable
select * from dbo.Promotion_Detail as a where exists (select id from @OrderTable as b where a.ID=b.OrderID);
declare @sql nvarchar(500);
set @sql='select * from @OrderTable select * from dbo.Promotion_Detail as a where exists (select id from '+@OrderTable+' as b where a.ID=b.OrderID);'
exec(@sql)
DECLARE @OrderTable NVARCHAR(128)='test'先print出来,如果是你想要的才把print改成exec
declare?@sql?nvarchar(500);
set?@sql='select?*?from??'+@OrderTable+'??select?*?from?dbo.Promotion_Detail?as?a?where?exists?(select?id?from???'+@OrderTable+'?as?b?where?a.ID=b.OrderID);'
print(@sql)
declare @sql nvarchar(500);
set @sql='select * from '+@OrderTable+' select * from dbo.Promotion_Detail as a where exists (select id from '+@OrderTable+' as b where a.ID=b.OrderID);'
exec(@sql)