sql server - UPDATE from a DERIVED QUERY - SQL -


i have update query run final scalar value based on derived query. need make sure correct row updated in outermost query. how can join derived2 query on rxtransactionid outermost query in example?

note: 'a.rxtransactionid' in clause not allowed. fact.adherence.rxtransactionid = a.rxtransactionid

update fact.adherence set fact.adherence.last_mpr = (  select last_mpr ( select derived1.irxlocationid, derived1.rxnumber, derived1.refillnumber, derived1.rxtransactionid, derived1.clientid, derived1.completeddate, derived1.nextcompleteddate, last_mpr = nullif(cast(cast(coalesce(dayssupply,    0) decimal)  / nullif(cast(coalesce(datediff(day, derived1.completeddate, derived1.nextcompleteddate), 0) decimal), 0)as decimal(12,4)), 0)     (select     [completeddate] [completeddate],     nextcompleteddate = (select  -- second recent complete date.     top 1 aa.[completeddate] fact.rxtransaction aa aa.rxid = c.rxid , coalesce(a.refillnumber + 1,0) = aa.refillnumber , aa.rxid = c.rxid),     a.rxnumber, [dayssupply], [refillnumber], c.[rxid], a.rxtransactionid, a.clientid, a.irxlocationid      [fact].[adherence]     inner join dimension.rx c on a.rxid = c.rxid     a.completeddate > dateadd(month, -6, getdate())     ) derived1 order irxlocationid, rxnumber, refillnumber desc) deriveda )  fact.adherence.rxtransactionid = a.rxtransactionid 

if put derived values , lookup key fact.adherence temp table can update statement on join of 2 tables.

there's example on how update joins here: update join example


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -