go
declare @sch_names varchar(50), @table_names varchar(50), @rwcounting int
set @sch_names='HumanResources'
set @table_names ='Employee'
set @rwcounting = 0
declare @fetchsql nvarchar(max)
set @fetchsql += 'select @rwcounting = count(1) as "countnum" from '+@sch_names+'.'+@table_names
exec(@fetchsql)
select @rwcounting
I am not getting the count from the table. Getting the count as zero. but expected count was 290.
1条答案
按热度按时间dxxyhpgq1#
Your code had three mistakes
1.review this code because you can't concatenate null with string
2.you must remove "as "countnum""
3.you must use sp_executesql for return ouput
this is correct