I want to change my SQL code which generates n table using two nested While loops, like:
DECLARE @count1 INT
SET @count1 = 2012
DECLARE @count2 INT
SET @count2 = 1
WHILE @count1 <= 2016
BEGIN
WHILE @count2 <= 12
create table LGDfigRecov as
select ...
from ...
WHERE FD0.mo_id=count2
AND FD0.an_id= count1
...
SET @count2 += 1
END
SET @count1 += 1
END
How can I change every time the name of new table like "LGDfigRecov +count1+count2"? It means I want to create every time a new table with the name of year and month at the end.
create table LGDfigRecov as select ...you need dynamic query