如何在if语句中的select中用表名参数?

[复制链接]
查看11 | 回复4 | 2017-9-18 17:30:37 | 显示全部楼层 |阅读模式
if not exists(select stationNum from @name1 where stationNum=@stationNum and stationDate=@time)
begin
....................
end
因为◎name1是动态生成的,必须用参数。请问怎么实现
回复

使用道具 举报

千问 | 2017-9-18 17:30:37 | 显示全部楼层
哪怎么得到execute的结果啊?
回复

使用道具 举报

千问 | 2017-9-18 17:30:37 | 显示全部楼层
declare @command varchar(1000)
set @command = 'select * from customers'
execute(@command)
执行之后就是结果阿!
回复

使用道具 举报

千问 | 2017-9-18 17:30:37 | 显示全部楼层
declare @command varchar(1000)
set @command = 'select stationNum into #temp from '+ @name1 + ...............
execute(@command)
if not exits(select * from #temp)
回复

使用道具 举报

千问 | 2017-9-18 17:30:37 | 显示全部楼层
Telamon,不错,不错。思路值得借鉴! 呵呵
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行