title: Cursor to fill data in table?
body: <pre><code>    CREATE TABLE [dbo].[Table_A](
          [ID] [int] IDENTITY(1,1) NOT NULL,
          [AREA] [varchar](50) NOT NULL,
          [Year] [int] NOT NULL,
          [Month] [int] NOT NULL,
          [Factor] [float] NULL,
          [Net] [float] NULL,
          [Path] [varchar](255) NULL,
          [Created] [smalldatetime] NULL,
          [CreatedBy] [varchar](50) NOT NULL,
          [LastModified] [varchar](50) NOT NULL,
          [LastModifiedBy] [varchar](50) NOT NULL)
      )
  
  ALTER TABLE [dbo].[Table_A] ADD  DEFAULT ((1.0)) FOR [Factor]
  GO
  
  ALTER TABLE [dbo].[Table_A] ADD  DEFAULT (sysdatetime()) FOR [Created]
  GO
  
  ALTER TABLE [dbo].[Table_A] ADD  DEFAULT (suser_name()) FOR [CreatedBy]
  GO
  
  ALTER TABLE [dbo].[Table_A] ADD  DEFAULT (sysdatetime()) FOR [LastModified]
  GO
  
  ALTER TABLE [dbo].[Table_A] ADD  DEFAULT (suser_name()) FOR [LastModifiedBy]
  GO
  </code></pre>
  
  <p>I need to fill up the Table using cursor where 
  cursor should fetch data from 
  Declare Cur_AREA Cursor
              For </p>
  
  <pre><code>Select Distinct Media From DIM_AREA
  </code></pre>
  
  <p>Note:DIM_AREA CONSISTS OF texas,dallas,chicago and newark.
    Cursor should fill data for years 1990 to 2020</p>
  
  <p>My cursor code is::</p>
  
  <pre><code>Declare @Temp_Year int
          Select @Temp_Year = MAX(Year) 
          While @Temp_Year &lt; DATEPART(YEAR, GETDATE())
          Begin
  
  Declare Cur_Media Cursor
              For 
              Select Distinct Media From DIM_AREA
              Order by Media
              open Cur_Media
              Fetch Next From Cur_Media
              While @@FETCH_STATUS = 0
              Begin
              Declare @Temp_Month int
                  Set @Temp_Month = 1
  
                  While @Temp_Month &lt;= 12
                  Begin
                      Insert into Table_A (Media, Year, month)
  
                      Set @Temp_Month = @Temp_Month + 1
                      Set @Temp_Year = @Temp_Year + 1
                      end
                      end
                      Close Cur_Media
              Deallocate Cur_Media
  </code></pre>
  
  <p>But my cursor not working properly :(</p>