Wednesday, 14 August 2013

Consolidate Multiple Select Results into One

Consolidate Multiple Select Results into One

I accidentally deleted a database table and had to restore it from an
outdated backup. I did something between the time I backed up and restored
that changed the results I am receiving from a certain query. I want five
results and it gives me seven because there are varying Color values for
the resulting rows. Somehow before I had it working perfectly. Here's my
SQL:
select LocationID, SUM(TransAmount) as TotalSales, DBAName, Color
from dbx.dbo.SampleData
group by LocationID, DBAName, Color
It used to give me:
LocationID TotalSales DBAName Color
267529000000 7660.51 FASTWAY #1 TACO BELL Red
267529000001 2681.801 FASTWAY #2 TACO BELL Orange
267529000002 3020.57 FASTWAY #3 TACO BELL Yellow
267529000003 3062.63 FASTWAY #4 TACO BELL Green
267529000004 3401.36 FASTWAY #5 TACO BELL Blue
But now with seemingly the same data it gives me:
LocationID TotalSales DBAName Color
267529000000 2183.26 FASTWAY #1 TACO BELL Indigo
267529000000 2901.48 FASTWAY #1 TACO BELL Red
267529000000 2575.77 FASTWAY #1 TACO BELL Violet
267529000001 2681.80 FASTWAY #2 TACO BELL Orange
267529000002 3020.57 FASTWAY #3 TACO BELL Yellow
267529000003 3062.63 FASTWAY #4 TACO BELL Blue
267529000004 3401.36 FASTWAY #5 TACO BELL Green
It always had Indigo and Violet as colors but disregarded them and used
Red as the main one. Any ideas? Tricks to get around this frustrating
occurrence? Thanks!

No comments:

Post a Comment