十分郁闷的问题!!差点把电脑砸掉
set @sqlstr= 'select top '+@temp+ 'GoodRecordNumber from tb_GoodRecord order by GoodRecordID desc '
exec(@sqlstr)
除了以上的方法~还有其他的办法吗?用exec的话就取不到查询出来的值了!我现在想把查询出来的值拿来当条件使用?各位帮我解决解决问题吧!我差点没有把电脑砸了
------解决方案--------------------已pubs数据库的authors表为例
declare @num int
declare @sqlstr varchar(8000)
set @num=4
exec( 'select * into tablename from (select top '+@num+ ' * from authors order by city desc)t ')
select * from tablename
-----
672-71-3249 Yokomoto Akiko 415 935-4228 3 Silver Ct. Walnut Creek CA 94595 1
893-72-1158 McBadden Heather 707 448-4982 301 Putnam Vacaville CA 95688 0
267-41-2394 O 'Leary Michael 408 286-2428 22 Cleveland Av. #14 San Jose CA 95128 1
486-29-1786 Locksley Charlene 415 585-4620 18 Broadway Av. San Francisco CA 94130 1