22,298
社区成员
发帖
与我相关
我的任务
分享
select @totalcount=count(id) from @tablename
exec('select '+@totalcount+'=count(id) from '+@tablename)
declare @totalcount int
declare @sql nvarchar(2000)
set @sql='select @t=count(id) from '+@tablename
exec sp_executesql @sql,N'@t varchar(1000) output',@totalcount output
print @totalcount
declare @totalcount int
declare @sql nvarchar(2000)
declare @t varchar(1000)
set @sql='select @t=count(id) from '+@tablename
exec sp_executesql @sql,N'@t varchar(1000) output','@totalcount int output'
print @totalcount
create table tb (id int,name varchar(10))
insert into tb select 1,'a'
insert into tb select 2,'b'
insert into tb select 3,'c'
insert into tb select 4,'d'
declare @tbname nvarchar(20)
set @tbname= 'tb'
declare @i int,@sql nvarchar(1000)
set @sql= 'select @i=count(1) from '+@tbname
exec sp_executesql @sql,N'@i int output' ,@i out
select @i
declare @totalcount int
declare @sql nvarchar(2000)
set @sql='select @totalcount=count(id) from '+@tablename
exec sp_executesql @sql
set @sql='select @totalcount=count(id) from '+@tablename
declare @sql nvarchar(2000)
set @sql='select @totalcount=count(id) from '+@tablename
delare @t int
exec sp_executesql @sql,N'@totalcount int output',@t int output
print @t