Casey, 

I'm not a DB Guru unlike Rudy but here's a stab. I believe you are pretty close. You 
need to join your tables instead of the where criteria and put the cust_id in your 
select.

SELECT 
        A.ORDER_NO, 
        A.SOLD_TO_CUST_ID, 
        B.NAME1(1), 
        A.BILL_TO_CUST_ID, 
        B.CUST_ID,
        A.ORDER_GRP,
FROM 
        PS_ORD_HEADER A INNER JOIN
        PS_CUSTOMER B ON 
        A.SOLD_TO_CUST_ID = B.CUST_ID
WHERE 
        A.ORDER_NO = 'OE-1062283'


-----Original Message-----
From: Casey Crookston [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 27, 2002 2:06 PM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] Help building a query


Okay,

My SQL knowledge is limited to simple selects, so I'm going to need some
help with this one.  The first part is easy:


(I hope email does not screw up the fowmatting too much)


SELECT ORDER_NO, SOLD_TO_CUST_ID, BILL_TO_CUST_ID, ORDER_GRP,

FROM PS_ORD_HEADER 

WHERE ORDER_NO = 'OE-1062283'


Easy enough.  BUT, I now need to join customer names to these customer
id's.  Orders are stored in PS_ORD_HEADER and Customers are stored in
PS_CUSTOMER. Trouble is, I need to pull the customer name (NAME1) from
the same table TWICE in the same query based once on the SOLD_TO_ID and
then again on the BILL_TO_ID.

I've aded the (1) and (2) to distinguish between the two, knowing that
it's not correct SQL syntax, but just to show the logic.


SELECT 
        A.ORDER_NO, 
        A.SOLD_TO_CUST_ID, 
        B.NAME1(1), 
        A.BILL_TO_CUST_ID, 
        B.NAME1(2),
        A.ORDER_GRP,
FROM 
        PS_ORD_HEADER A, 
        PS_CUSTOMER B
WHERE 
        A.ORDER_NO = 'OE-1062283'
        AND 
        ?? A.SOLD_TO_CUST_ID = B.CUST_ID ??


I have no idea how to pull one field from the same record twice in the
same query based on two separate key fields for two separate results.

Phew.... I hope that made sense.

Casey

____ * The WDVL Discussion List from WDVL.COM * ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] 
       Send Your Posts To: [EMAIL PROTECTED]
To change subscription settings to the wdvltalk digest version:
    http://wdvl.internet.com/WDVL/Forum/#sub

________________  http://www.wdvl.com  _______________________

You are currently subscribed to wdvltalk as: [EMAIL PROTECTED]
To unsubscribe send a blank email to %%email.unsub%%

____ � The WDVL Discussion List from WDVL.COM � ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED]
       Send Your Posts To: [EMAIL PROTECTED]
To change subscription settings to the wdvltalk digest version:
    http://wdvl.internet.com/WDVL/Forum/#sub

________________  http://www.wdvl.com  _______________________

You are currently subscribed to wdvltalk as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]

Reply via email to