Wanting to know how to get the output of the following dynamic query into a variable that can be used in while loop in SQL. This gives me the result I am looking for in the results window. Just need to get it into a usable variable once in a stored procedure.
declare @DynQry varchar(max)
declare @rotpos int = 2
declare @rotID int = 3
set @DynQry = '
select ShiftID'+CAST(@rotpos as nvarchar(10))+' from dbo.Rotations where RotationID = '+CAST(@rotID as nvarchar(10))+';
'
EXEC (@DynQry);