DECLARE @command = 'SELECT CASE WHEN ( SELECT COUNT(*)
FROM [table] WITH ( NOLOCK )
WHERE DATEDIFF(minute, systemupdatedtimestamp, GETDATE()) < 10
) > 0 THEN 0
ELSE 1
END'
Now I need to get the ‘return value’ of the above command (0 or 1).
EXEC(@commnad)
How do I get the return value from the above?
I tried
SET @ReturnValue = EXEC(@command)
but no luck.
use sp_executesql
in your case it is something like:
Update:
To follow up on you comment. If you do not want to modify the original string containing your sql command (e.g. it is used in other places etc) you can wrap that command inside a new string something like:
And call sp_executesql in the same way as above.