Front Office Football Central  

Go Back   Front Office Football Central > Archives > FOFC Archive
Register FAQ Members List Calendar Mark Forums Read Statistics

Reply
 
Thread Tools
Old 05-25-2006, 08:45 AM   #1
Bonegavel
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:
# | vendor | location | orderstatus ------------------------------------ 1 | ABC | townA | 2 2 | 123 | townB | 2 3 | ABC | townA | 1 4 | ABC | townA | 2 5 | 123 | townB | 2

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).

Bonegavel is offline   Reply With Quote
Old 05-25-2006, 08:52 AM   #2
sachmo71
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.
sachmo71 is offline   Reply With Quote
Old 05-25-2006, 09:03 AM   #3
VPI97
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.
VPI97 is offline   Reply With Quote
Old 05-25-2006, 09:05 AM   #4
Raven Hawk
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
__________________
Owner of The Shreveport Pride in The CFL

Last edited by Raven Hawk : 05-25-2006 at 09:07 AM.
Raven Hawk is offline   Reply With Quote
Old 05-25-2006, 09:58 AM   #5
Bonegavel
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.
Bonegavel is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT -5. The time now is 12:03 AM.



Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.