Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
masond
Constraint Violating Yak Guru
447 Posts |
Posted - 2013-10-09 : 11:42:57
|
Hey guys I need some help Aim- Join both results together, if there is a parentid, in both #MSIP and other query, then do an update, and update the sales column to reflect the correct amountFor eg Parentid Parent_Name SalesMSIP 878201390886 ABERDEEN UNIVERSITY 16563736.36 878201390886 ABERDEEN UNIVERSITY 4289717.05Results 878201390886 ABERDEEN UNIVERSITY 20853453.41-- Date Declaration Omnipay rolling12-- Declare @R12Omni datetimeset @R12Omni = (select dateadd(MM,-11,max(Period))from [FDMS].[dbo].[Fact_Omnipay_Profitability])select @R12OmniSELECT Dim_Outlet.ParentID, Dim_Outlet.Parent_Name,sum( Fact_Financial_History_2.hst_sales_amt_R12) as Salesinto #MSIP FROM Fact_Financial_History_2 INNER JOINDim_Outlet ON Fact_Financial_History_2.hst_merchnum = Dim_Outlet.FDMSAccountNo_First9where Agent_Chain_No not in ('878970059886', '878970013883')AND fdmsaccountno NOT IN (SELECT [ta_mid] FROM fdms_partnerreporting.tmp.trade_assocations)and Account_Status ='16'group by ParentID,Parent_Namehaving SUM (hst_sales_amt_R12) > 1999999--order by Parent_Name asc union all SELECT ParentID,Dim_Outlet.Parent_Name, Sum([Tot_Purch_Amt]) as 'Sales'FROM Fact_Omnipay_Profitability INNER JOIN Dim_Outlet ON Fact_Omnipay_Profitability.FDMSAccountNo = Dim_Outlet.FDMSAccountNowhere Period >= @R12Omnigroup by Dim_Outlet.ParentID,Parent_Name |
|
masond
Constraint Violating Yak Guru
447 Posts |
Posted - 2013-10-09 : 11:49:12
|
i believe the update be something along the lines of update #MSIPset ParentID = where (SELECT coalesce (SUM(Sales),0) FROM #MSIPwhere ParentID = ParentID group by ParentID |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-09 : 13:04:19
|
sonds like thisupdate mset m.Sales = m.Sales + tmp.SalesFROM #MSIP mINNER JOIN (SELECT ParentID,Dim_Outlet.Parent_Name, Sum([Tot_Purch_Amt]) as 'Sales'FROM Fact_Omnipay_Profitability INNER JOIN Dim_Outlet ON Fact_Omnipay_Profitability.FDMSAccountNo = Dim_Outlet.FDMSAccountNowhere Period >= @R12Omnigroup by Dim_Outlet.ParentID,Parent_Name)tmpON tmp.Parent_Name = m.Parent_NameAND tmp.ParentID = m.ParentID ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|
|
|