日期:2014-05-19  浏览次数:20533 次

以下语句是错的,怎么办?

DECLARE
@fcount     as   int     --记录数
set   @fcount=0
exec   ( 'select   '+@fcount+ '=count(*)   from   t_ICItem   where   fnumber   not   in   (select   fnumber   from   t_ICItem) ')
print   1
我想要执行的结果,记录数是否> 0怎么办?

------解决方案--------------------
DECLARE @fcount as int --记录数
declare @sql nvarchar(4000)
set @sql= 'select @fcount=count(*) from t_ICItem where fnumber not in (select fnumber from t_ICItem) '
exec sp_executesql @sql, N '@fcount int output ', @fcount output
select @fcount
------解决方案--------------------
---直接
select @fcount=count(*) from t_ICItem where fnumber not in (select fnumber from t_ICItem)
---就行,或者用 sp_executesql