|
PWilson
Starting Member
1 Post |
Posted - 2002-06-10 : 18:03:25
|
Hi I was wondering if anyone can help me with this query. I am getting an invalid column name error message on "Qtr1Cnt" and "Qtr1PLCTot" (etc. through Qtr4) columns. Also, I realize that pivoting and cross tabbing are expensive operations but unfortunately I'm not sure how to write this in a stored procedure... Here's the code:select Name, BusinessPartner, UserName, Email, OptVal, BPName,Quarter1CountTotal as Q1Cnt, sum(cast(Quarter1PLCTotal as money)) as Q1PLCTot,Quarter2CountTotal as Q2Cnt, sum(cast(Quarter2PLCTotal as money)) as Q2PLCTot,Quarter3CountTotal as Q3Cnt, sum(cast(Quarter3PLCTotal as money)) as Q3PLCTot,Quarter4CountTotal as Q4Cnt,sum(cast(Quarter4PLCTotal as money)) as Q4PLCTotfrom ( select a.Name "Name", a.BP "BusinessPartner", a.UserName "UserName", a.Email "Email", b.OptVal "OptVal",b.BPName "BPName", count(c.DateTimeKey) "Quarter1CountTotal",c.PLCEst "Quarter1PLCTotal",0 "Quarter2CountTotal", 0 "Quarter2PLCTotal", 0 "Quarter3CountTotal", 0 "Quarter3PLCTotal", 0 "Quarter4CountTotal", 0 "Quarter4PLCTotal" from dbo.tUsers a, dbo.BP b, dbo.FallSpiff Cwherea.BP = b.OptVal andc.Owner = a.UserName andc.FinalStatus = 1 and((c.DE <> 1) and (c.CCD <> 1)) and(cast(c.CloseDate as DateTime)) > '2002-01-01 00:00:00.000' and(cast(c.CloseDate as DateTime)) < '2002-04-01 00:00:00.000'unionselect a.Name "Name", a.BP "BusinessPartner", a.UserName "UserName", a.Email "Email", b.OptVal "OptVal",b.BPName "BPName", 0, 0, count(c.DateTimeKey), c.PLCEst, 0, 0, 0, 0 from dbo.tUsers a, dbo.BP b, dbo.FallSpiff Cwherea.BP = b.OptVal andc.Owner = a.UserName andc.FinalStatus = 1 and((c.DE <> 1) and (c.CCD <> 1)) and(cast(c.CloseDate as DateTime)) > '2002-04-01 00:00:00.000' and(cast(c.CloseDate as DateTime)) < '2002-07-01 00:00:00.000'unionselect a.Name "Name", a.BP "BusinessPartner", a.UserName "UserName", a.Email "Email", b.OptVal "OptVal",b.BPName "BPName", 0, 0, 0, 0, count(c.DateTimeKey), c.PLCEst, 0, 0 from dbo.tUsers a, dbo.BP b, dbo.FallSpiff Cwherea.BP = b.OptVal andc.Owner = a.UserName andc.FinalStatus = 1 and((c.DE <> 1) and (c.CCD <> 1)) and(cast(c.CloseDate as DateTime)) > '2002-07-01 00:00:00.000' and(cast(c.CloseDate as DateTime)) < '2002-10-01 00:00:00.000'unionselect a.Name "Name", a.BP "BusinessPartner", a.UserName "UserName", a.Email "Email", b.OptVal "OptVal",b.BPName "BPName", 0, 0, 0, 0, 0, 0, count(c.DateTimeKey), c.PLCEst from dbo.tUsers a, dbo.BP b, dbo.FallSpiff Cwherea.BP = b.OptVal andc.Owner = a.UserName andc.FinalStatus = 1 and((c.DE <> 1) and (c.CCD <> 1)) and(cast(c.CloseDate as DateTime)) > '2002-10-01 00:00:00.000' and(cast(c.CloseDate as DateTime)) < '2002-01-02 00:00:00.000') QuarterSpiff group by Name, BusinessPartner, UserName, Email, OptVal, BPName, Q1Cnt, Q1PLCTot,Q2Cnt, Q2PLCTot, Q3Cnt, Q3PLCTot, Q4Cnt, Q4PLCTot |
|