![]() |
|
|
#1 | ||
|
Awaiting Further Instructions...
Join Date: Nov 2001
Location: Macungie, PA
|
tSQL help
Table: order
fields: vendor, orderstatus, location I want to select only records where: orderstatus = 2 and the vendor and locations are identical. example table (obviously not my actual table) Code:
the query i'm trying to build will only return 1,2,4,5 (with the pairs being 1 and 4 and 2 and 5). I'm guessing I need to do a join of some sort and would appreciate any help even if that help is a site. I'm using MS Sql server 2000 (which is tSql just for clarification). |
||
|
|
|
|
|
#2 |
|
The boy who cried Trout
Join Date: Oct 2000
Location: TX
|
the data in the vendor and location columns are identical? how about a group by statement?
Do you have a list of the vendors you want? so select * from order where orderstatus = 2 and vendors in (n,n,n,etc) Last edited by sachmo71 : 05-25-2006 at 08:53 AM. |
|
|
|
|
|
#3 |
|
Hokie, Hokie, Hokie, Hi
Join Date: Mar 2001
Location: Kennesaw, GA
|
Try this:
select [order].vendor, [order].location, [order].orderstatus from [order], (select vendor, location, orderstatus, count(*) as cnt from [order] where (orderstatus = 2) group by vendor, location, orderstatus having count(*) > 1) AS dups where [order].vendor = dups.vendor and [order].location = dups.location and [order].orderstatus = 2 Last edited by VPI97 : 05-25-2006 at 09:04 AM. |
|
|
|
|
|
#4 |
|
College Starter
Join Date: Mar 2002
Location: Thunderdome
|
Seems like relatively straight forward 'Where' and 'Group By' clauses unless I'm missing something. I'm not too familiar with tSQL, much more PL SQL, but this what I'd be thinking:
WHERE order.status = 2 GROUP BY order.vendor, order.location, order.status Last edited by Raven Hawk : 05-25-2006 at 09:07 AM. |
|
|
|
|
|
#5 |
|
Awaiting Further Instructions...
Join Date: Nov 2001
Location: Macungie, PA
|
Thanks everyone for the assistance!
VPI97's example worked perfectly (with slight tweaking to take other things into consideration that i didn't bog this post down with). Raven Hawk, I think your example would still show me everyone with a status of 2 regardless if they weren't duplicate. |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|