| Author |
Topic |
|
bsheridan
Starting Member
3 Posts |
Posted - 2008-08-08 : 02:05:43
|
| I'm trying to run Audit data for our network. Here is the way the data is stored.ID DATE Order Site Wrong Overpick Damage Missing1 1/1/2008 7456345 NY 0 0 0 02 1/1/2008 8234645 NV 1 1 1 13 1/1/2008 1657768 PA 0 0 4 04 1/1/2008 3452345 CA 1 2 0 05 1/1/2008 2456524 KS 0 0 3 06 1/2/2008 4345345 NY 0 0 0 07 1/2/2008 8554345 NV 4 1 1 48 1/2/2008 3242343 PA 0 0 0 09 1/2/2008 2340505 CA 0 0 0 010 1/2/2008 3214234 KS 2 1 1 1I'm trying to output the results like this Total Orders Failed Orders Total Errors Wrong OverPick Damage Missing1/1/2008 5 4 14 2 3 8 11/2/2008 5 2 15 6 2 2 5 Total Orders: Count of ID's grouped in the DateFailed Orders: Should check to see if "wrong, overpick, damage, missing are > 0. that marks it as a failed order.Total Errors: Sum of wrong, overpick, damage, missing If anyone can help me with this query I would much appreciate it. I'm at a stand still on this.Thanks, |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-08-08 : 02:27:24
|
quote: Originally posted by bsheridan I'm trying to run Audit data for our network. Here is the way the data is stored.ID DATE Order Site Wrong Overpick Damage Missing1 1/1/2008 7456345 NY 0 0 0 02 1/1/2008 8234645 NV 1 1 1 13 1/1/2008 1657768 PA 0 0 4 04 1/1/2008 3452345 CA 1 2 0 05 1/1/2008 2456524 KS 0 0 3 06 1/2/2008 4345345 NY 0 0 0 07 1/2/2008 8554345 NV 4 1 1 48 1/2/2008 3242343 PA 0 0 0 09 1/2/2008 2340505 CA 0 0 0 010 1/2/2008 3214234 KS 2 1 1 1I'm trying to output the results like this Total Orders Failed Orders Total Errors Wrong OverPick Damage Missing1/1/2008 5 4 14 2 3 8 11/2/2008 5 2 15 6 2 2 5 Total Orders: Count of ID's grouped in the DateFailed Orders: Should check to see if "wrong, overpick, damage, missing are > 0. that marks it as a failed order.Total Errors: Sum of wrong, overpick, damage, missing If anyone can help me with this query I would much appreciate it. I'm at a stand still on this.Thanks,
That is not fitting.Please provide some code for take data in a tmp table and describe exactly your desired result.Webfred |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-08-08 : 02:38:51
|
[code]DECLARE @TABLE TABLE( [ID] int, [DATE] datetime, [Order] int, Site varchar(2), Wrong int, Overpick int, Damage int, Missing int)INSERT INTO @TABLESELECT 1, '1/1/2008', 7456345, 'NY', 0, 0, 0, 0 UNION ALLSELECT 2, '1/1/2008', 8234645, 'NV', 1, 1, 1, 1 UNION ALLSELECT 3, '1/1/2008', 1657768, 'PA', 0, 0, 4, 0 UNION ALLSELECT 4, '1/1/2008', 3452345, 'CA', 1, 2, 0, 0 UNION ALLSELECT 5, '1/1/2008', 2456524, 'KS', 0, 0, 3, 0 UNION ALLSELECT 6, '1/2/2008', 4345345, 'NY', 0, 0, 0, 0 UNION ALLSELECT 7, '1/2/2008', 8554345, 'NV', 4, 1, 1, 4 UNION ALLSELECT 8, '1/2/2008', 3242343, 'PA', 0, 0, 0, 0 UNION ALLSELECT 9, '1/2/2008', 2340505, 'CA', 0, 0, 0, 0 UNION ALLSELECT 10, '1/2/2008', 3214234, 'KS', 2, 1, 1, 1SELECT [DATE], [Total Orders] = COUNT([ID]), [Total Failed] = SUM(CASE WHEN Wrong > 0 OR Overpick > 0 OR Damage > 0 OR Missing > 0 THEN 1 ELSE 0 END), [Total Errors] = SUM(Wrong + Overpick + Damage + Missing), Wrong = SUM(Wrong), Overpick = SUM(Overpick), Damage = SUM(Damage), Missing = SUM(Missing)FROM @TABLEGROUP BY [DATE]/*DATE Total Orders Total Failed Total Errors Wrong Overpick Damage Missing ------------ ------------ ------------ ------------ ----------- ----------- ----------- ----------- 2008-01-01 5 4 14 2 3 8 1 2008-01-02 5 2 15 6 2 2 5 (2 row(s) affected)*/[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-08-08 : 03:01:27
|
quote: Originally posted by webfred
quote: Originally posted by bsheridan I'm trying to run Audit data for our network. Here is the way the data is stored.ID DATE Order Site Wrong Overpick Damage Missing1 1/1/2008 7456345 NY 0 0 0 02 1/1/2008 8234645 NV 1 1 1 13 1/1/2008 1657768 PA 0 0 4 04 1/1/2008 3452345 CA 1 2 0 05 1/1/2008 2456524 KS 0 0 3 06 1/2/2008 4345345 NY 0 0 0 07 1/2/2008 8554345 NV 4 1 1 48 1/2/2008 3242343 PA 0 0 0 09 1/2/2008 2340505 CA 0 0 0 010 1/2/2008 3214234 KS 2 1 1 1I'm trying to output the results like this Total Orders Failed Orders Total Errors Wrong OverPick Damage Missing1/1/2008 5 4 14 2 3 8 11/2/2008 5 2 15 6 2 2 5 Total Orders: Count of ID's grouped in the DateFailed Orders: Should check to see if "wrong, overpick, damage, missing are > 0. that marks it as a failed order.Total Errors: Sum of wrong, overpick, damage, missing If anyone can help me with this query I would much appreciate it. I'm at a stand still on this.Thanks,
That is not fitting.Please provide some code for take data in a tmp table and describe exactly your desired result.Webfred
Ok kh i take it back In the future I will try to not answer to something I don't understand because there are always people who understand...Webfred |
 |
|
|
bsheridan
Starting Member
3 Posts |
Posted - 2008-08-08 : 03:04:43
|
THANK YOU khtanquote: Originally posted by khtan
DECLARE @TABLE TABLE( [ID] int, [DATE] datetime, [Order] int, Site varchar(2), Wrong int, Overpick int, Damage int, Missing int)INSERT INTO @TABLESELECT 1, '1/1/2008', 7456345, 'NY', 0, 0, 0, 0 UNION ALLSELECT 2, '1/1/2008', 8234645, 'NV', 1, 1, 1, 1 UNION ALLSELECT 3, '1/1/2008', 1657768, 'PA', 0, 0, 4, 0 UNION ALLSELECT 4, '1/1/2008', 3452345, 'CA', 1, 2, 0, 0 UNION ALLSELECT 5, '1/1/2008', 2456524, 'KS', 0, 0, 3, 0 UNION ALLSELECT 6, '1/2/2008', 4345345, 'NY', 0, 0, 0, 0 UNION ALLSELECT 7, '1/2/2008', 8554345, 'NV', 4, 1, 1, 4 UNION ALLSELECT 8, '1/2/2008', 3242343, 'PA', 0, 0, 0, 0 UNION ALLSELECT 9, '1/2/2008', 2340505, 'CA', 0, 0, 0, 0 UNION ALLSELECT 10, '1/2/2008', 3214234, 'KS', 2, 1, 1, 1SELECT [DATE], [Total Orders] = COUNT([ID]), [Total Failed] = SUM(CASE WHEN Wrong > 0 OR Overpick > 0 OR Damage > 0 OR Missing > 0 THEN 1 ELSE 0 END), [Total Errors] = SUM(Wrong + Overpick + Damage + Missing), Wrong = SUM(Wrong), Overpick = SUM(Overpick), Damage = SUM(Damage), Missing = SUM(Missing)FROM @TABLEGROUP BY [DATE]/*DATE Total Orders Total Failed Total Errors Wrong Overpick Damage Missing ------------ ------------ ------------ ------------ ----------- ----------- ----------- ----------- 2008-01-01 5 4 14 2 3 8 1 2008-01-02 5 2 15 6 2 2 5 (2 row(s) affected)*/ KH[spoiler]Time is always against us[/spoiler]
|
 |
|
|
bsheridan
Starting Member
3 Posts |
Posted - 2008-08-08 : 03:36:34
|
| Hey Guys thanks for your help. I have one more question. Lets say I have another table that has total shipmentstblOrdersShippedDate | Shipments | Site---------------------------01/01/2008, 2343, NY01/01/2008, 2343, PACan I include total shipments in the other query output on those dates aswell?? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-08-08 : 05:41:34
|
just use INNER JOIN KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|