Roland Alexander STL (1/2/2013)
Well, it's not printing anything because @totalrecs is NULL when you concatentate it, and NULL concatenated with anything else yields NULL. You will need to assign @totalrecs a value. Why don't you just move all this into a stored procedure rather than trying to build a string and then execute it?
Surely @totalrecs would be the figure which is remaining??
declare @totalrecs int
select @totalrecs=999
set @totalrecs=2000-@totalrecs
print @totalrecs