日期:2014-05-18 浏览次数:20442 次
declare @date varchar(10) declare @month int declare @year int set @month=datepart(mm,getdate()) set @year=datepart(yy,getdate()) exec('select distinct convert(varchar(10),logindate,120) from dbo.BoxLogMonth'+@year+@month+' where datediff(dd,logindate,getdate())=1')
declare @num int, @sqls nvarchar(4000) set @sqls='select count(*) from tableName' exec(@sqls) --如何将exec执行结果放入变量中? declare @num int, @sqls nvarchar(4000) set @sqls='select @a=count(*) from tableName ' exec sp_executesql @sqls,N'@a int output',@num output select @num