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 |
|
vmon
Yak Posting Veteran
63 Posts |
Posted - 2006-06-07 : 10:56:59
|
| Is there are way to group records from a table and get a count of the records where the group by does not group because of data differences. I want to group order lines by order number to see if any lines on an order has different schedule dates. I am not sure how to get count to do this. Here is what it looks like right now. The count is giving me the number of lines and I only want to know if an order has two different dates. Will I have to use a cursor or is is possible with a select? Thanks for your help.SELECT OrderNumber, ScheduledDate, LineDueDate, DeliveryDate, COUNT(*) AS LinesFROM dbo.tblScheduleGROUP BY OrderNumber, ScheduledDateORDER BY OrderNumber |
|
|
vmon
Yak Posting Veteran
63 Posts |
Posted - 2006-06-07 : 11:13:49
|
| Figured out my on problem. Here is what I did. THis gave me the order numbers and the line on the orders where the dates on the lines do not match for the order. SELECT OrderNumber, COUNT(*) AS OrdersFROM (SELECT OrderNumber, ScheduledDate, LineDueDate, DeliveryDate FROM dbo.tblSchedule GROUP BY OrderNumber, ScheduledDate, LineDueDate, DeliveryDate, OrderNumber) DERIVEDTBLGROUP BY OrderNumberHAVING (COUNT(*) > 1)ORDER BY COUNT(*) DESC |
 |
|
|
|
|
|
|
|