i'm using sql server 2005 for my asp.net program.
i have 2 tables, first table X, second table Y
X has column:

``````DEM_ID int
DEM_DATE datetime
DEM_QTY numeric(18,0)
constraint PK_DEMAND primary key nonclustered (DEM_ID)``````

Y has column:

``````FRC_ID int
FRC_YEAR numeric(4)
FRC_MON numeric(2)
FRC_SALES numeric(18,0)
FRC_FRCSALES numeric(18,0)
FRC_FRCLOG numeric(18,0)
constraint PK_FORECASTSALES primary key nonclustered (FRC_ID)``````

What i want to do is put each month and year from col dem_date in table X to col frc_year and frc_mon in table Y and put sum dem_qty per mon and year to frc_sales. and then get frc_frcsales row values from calculation (e.g for row 90 = (4*89th row in col frc_sales)+(6*84th row in col frc_sales+....), for row 91 =(4*90th row in col frc_sales)+(6*85th row in col frc_sales+....) ) and continues everytime i had new row on table X.

Best Regards & Thanks.

``````SELECT MONTH(DEM_DATE),YEAR(DEM_DATE), SUM(DEM_QTY)
FROM X GROUP BY MONTH(DEM_DATE),YEAR(DEM_DATE)``````

NOW YOU WILL GET MOnth,year & its corresponding sales. So apply left join X with Y. LIKE `Y left join X on y.month=x.month AND y.year=x.year` TRY WITH YOURSELF first then let us know.

thank you, i solved it.
now i just don't get how to fill the next row of frc_frcsales with calculation i have based on some values in rows from frc_sales.

Thanks and Regards