I have a question on this Cnt.
This query I make it as outer cursor query
SELECT DNum,LNum,Cd,count([EMployeeUI]) TotalEmployees
FROM dbo.Temp
WHERE EMployeeUI IS NOT NULL
group by DNum,LNum,Cd
Now in the Insert into main table I have a case logic ( Now how I can refer Cnt form the outer cursor query?
case when (Cnt.TotalEmployees is not null or Cnt.TotalEmployees >0) then (T1.FRGN_AMT / Cnt.TotalEmployees) else 0 end,