Declare @count nvarchar(max)
set @count ='select COUNT(*) from '+ @tablename+''
if( @count =0 )
begin
print 'fail'
end
else
begin
print 'success'
end
end
the @count variable is not getting the value 0. it shows the error as
Conversion failed when converting the nvarchar value ‘select COUNT(*) from tablename’ to data type int.
This should work: