Question : Create Dynamic Cursor

In FoxPro, I was able to create a dynamic cursor based on the current date minus x.  Can this be replicated in T-SQL?  The code below is exactly how I have done it with FoxPro.

-- Create the Results cursor - a couple standard fields, then monthly payment fields
cCoder = "state c(2), AssetCat c(4), YYYYMM c(6), InitialPool y"
dResultsDateCounter = dStartDate
iCounter = 0
DO WHILE dResultsDateCounter < GOMONTH(DATE(),-1)
      iCounter = iCounter + 1
      cCoder = cCoder + ", Month" + PADL(ALLTRIM(STR(iCounter)),2,'0') + " y"
      dResultsDateCounter = GOMONTH(dResultsDateCounter,1)
ENDDO
CREATE CURSOR Results (&cCoder.)

Answer : Create Dynamic Cursor

Sure this can be replicated in TSQL.
Can you explain a bit more what you are trying to achieve (ie why you need cursor)?
To give full syntax, more details about the tables and results will be needed.

I if understnad corretly, you want to have a cursor that has a column for each month from january until month of yesterday?
Random Solutions  
 
programming4us programming4us