日期:2014-05-17 浏览次数:20492 次
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)