I'm new to SQL and need help. The table below duplicates the row when there is a value for "open quotes."
I'm using SQL 2008 and accessing it with SQL server management studio by Microsoft.
Here's the query:
select distinct CUSTID_32, MonthlyRentals, DailyRentals, FreightCharges, Total,
case
when (ContactType like 'quo%'
and ActionDate >= DATEADD(month,-3,getdate())
and ActionDate <= DATEADD(month,5,getdate())
and WorkflowStatus not like 'Rej%'
and WorkflowStatus not like 'Real%')
then Synergy.dbo.AAASynergyWorkflow_vw.ActionDate else '' end as OpenQuote
from ExactMAXBunnell.dbo.TwelveMonthRentalRevenue_vw
left join synergy.dbo.AAASynergyWorkflow_vw
on ExactMAXBunnell.dbo.TwelveMonthRentalRevenue_vw.CUSTID_32 = Synergy.dbo.AAASynergyWorkflow_vw.Cust#
where Total >= 20000
group by CUSTID_32, MonthlyRentals, DailyRentals, FreightCharges, Total, ContactType, ActionDate, WorkflowStatus
Here are the results:
CUSTID_32 MonthlyRentals DailyRentals FreightCharges Total OpenQuote
BA300 14000 57702 12116.76 83818.76
BC020 36400 0 0 36400
BR430 0 19116 1668.22 20784.22
CA120 0 59649 731 60380
CH340 0 72924 13823.09 86747.09
CH340 0 72924 13823.09 86747.09 10/31/2013
CH360 0 129741 7276.07 137017.07
CH420 0 37524 5439.21 42963.21
CH600 0 23010 365.5 23375.5
FL100 0 119652 8312.17 127964.17
HI010 16800 9381 1215.57 27396.57
HI010 16800 9381 1215.57 27396.57 11/30/2013
HU590 0 58056 6048 64104
IL040 0 44250 3655 47905
IN070 25200 42834 2407.47 70441.47
IN070 25200 42834 2407.47 70441.47 10/31/2013
IN080 8400 22656 2277.67 34064.67
LA030 33600 0 0 33600
LE350 0 53631 1908.05 55539.05
MI010 0 19293 2193 21486
MI010 0 19293 2193 21486 10/31/2013
MI120 0 65667 7516.26 73183.26
MI520 0 111333 1827.5 113160.5
NC020 14000 16815 3560.04 34375.04
NV020 36400 28674 2565 68665
NV050 0 33984 2664.18 36648.18
PA030 25200 18231 3181.37 46612.37
RO120 0 32568 4447.68 37015.68
SC500 0 34161 2622.22 36783.22
SI400 11200 7434 5835.37 26086.55
SK010 0 45489 0 45489
ST530 0 144432 1208.76 145640.76
TX030 19600 60003 1296.5 80899.5
TX040 0 24426 7148.44 31574.44
TX060 33600 1239 5817.97 40656.97
TX120 5600 12390 2268.81 20258.81
VA370 0 32745 6268.13 39013.13
VA440 28000 7080 8411 43491
WI500 0 68743 955.2 69698.2
YO010 0 36462 4309.51 40771.51
As you can see any time there is a result for an open quote date the row returned is duplicated. Can someone explain this to me and provide a solution to remove the duplicate. As I am new to SQL any explanations that you can provide would be most helpful.
Many thanks in advance.
Cheers,
Ken
I'm using SQL 2008 and accessing it with SQL server management studio by Microsoft.
Here's the query:
select distinct CUSTID_32, MonthlyRentals, DailyRentals, FreightCharges, Total,
case
when (ContactType like 'quo%'
and ActionDate >= DATEADD(month,-3,getdate())
and ActionDate <= DATEADD(month,5,getdate())
and WorkflowStatus not like 'Rej%'
and WorkflowStatus not like 'Real%')
then Synergy.dbo.AAASynergyWorkflow_vw.ActionDate else '' end as OpenQuote
from ExactMAXBunnell.dbo.TwelveMonthRentalRevenue_vw
left join synergy.dbo.AAASynergyWorkflow_vw
on ExactMAXBunnell.dbo.TwelveMonthRentalRevenue_vw.CUSTID_32 = Synergy.dbo.AAASynergyWorkflow_vw.Cust#
where Total >= 20000
group by CUSTID_32, MonthlyRentals, DailyRentals, FreightCharges, Total, ContactType, ActionDate, WorkflowStatus
Here are the results:
CUSTID_32 MonthlyRentals DailyRentals FreightCharges Total OpenQuote
BA300 14000 57702 12116.76 83818.76
BC020 36400 0 0 36400
BR430 0 19116 1668.22 20784.22
CA120 0 59649 731 60380
CH340 0 72924 13823.09 86747.09
CH340 0 72924 13823.09 86747.09 10/31/2013
CH360 0 129741 7276.07 137017.07
CH420 0 37524 5439.21 42963.21
CH600 0 23010 365.5 23375.5
FL100 0 119652 8312.17 127964.17
HI010 16800 9381 1215.57 27396.57
HI010 16800 9381 1215.57 27396.57 11/30/2013
HU590 0 58056 6048 64104
IL040 0 44250 3655 47905
IN070 25200 42834 2407.47 70441.47
IN070 25200 42834 2407.47 70441.47 10/31/2013
IN080 8400 22656 2277.67 34064.67
LA030 33600 0 0 33600
LE350 0 53631 1908.05 55539.05
MI010 0 19293 2193 21486
MI010 0 19293 2193 21486 10/31/2013
MI120 0 65667 7516.26 73183.26
MI520 0 111333 1827.5 113160.5
NC020 14000 16815 3560.04 34375.04
NV020 36400 28674 2565 68665
NV050 0 33984 2664.18 36648.18
PA030 25200 18231 3181.37 46612.37
RO120 0 32568 4447.68 37015.68
SC500 0 34161 2622.22 36783.22
SI400 11200 7434 5835.37 26086.55
SK010 0 45489 0 45489
ST530 0 144432 1208.76 145640.76
TX030 19600 60003 1296.5 80899.5
TX040 0 24426 7148.44 31574.44
TX060 33600 1239 5817.97 40656.97
TX120 5600 12390 2268.81 20258.81
VA370 0 32745 6268.13 39013.13
VA440 28000 7080 8411 43491
WI500 0 68743 955.2 69698.2
YO010 0 36462 4309.51 40771.51
As you can see any time there is a result for an open quote date the row returned is duplicated. Can someone explain this to me and provide a solution to remove the duplicate. As I am new to SQL any explanations that you can provide would be most helpful.
Many thanks in advance.
Cheers,
Ken