Filling one table using another table in SQL Server -


i have 2 sql tables follows:

enter image description here

enter image description here

as may note, first table has monthly frequency (date column), while second table has quarterly frequency. here do:

  • for each issueid table 1, @ date, determine previous end of quarter, , go fetch data table 2 corresponding issue end of quarter, , insert in first table in last 2 columns.

  • for example: take issueid 123456 , date 1/31/2014. previous end of quarter 12/31/2013. go table 1, copy q_exp , q_act correspond issueid , 12/31/2013, , paste first table.

of course, fill entire first table , minimize manual inserts.

any appreciated! thanks!

try following query

update issues set q_exp=(select top 1 q.q_exp            quarterlytable q            q.issueid=i.issueid            , q.[date]<=i.[date]            order q.[date] desc) ,q_act=   (select top 1 q.q_act            quarterlytable q            q.issueid=i.issueid            , q.[date]<=i.[date]            order q.[date] desc) issues 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -