where clause

  • Hi everybody!

    Right now I have this select statement

    SELECT PO_Number, Part_Number

    FROM OrderItem

    WHERE

    Part_Number IN (@Part_Number1,@Part_Number2,@Part_Number3,@Part_Number4,@Part_Number5) and

    PO_Number IN (@PO_Number1,@PO_Number2,@PO_Number3,@PO_Number4,@PO_Number5)

    The translation of the statement I need is: Bring the data where Part Number is equal to PartNumber1, which belongs to PO Number1, Part Number2, which belongs to PO Number2, etc...

    So the ideal situation is 5 Part Numbers for 5 PO Numbers. Each Part Number corresponding to one PO. (Part Number1 to PO Number1, Part Number2 to PO Number2,etc...)

    The result will be 5 records.

    But what if Part Number1 belongs to PO Number1 and PO Number2. The result will be 6 records. And I'm trying to avoid this.

    Unfortunately I can't find the correct where clause. Can anybody help???

    Thanks a lot,

    Durug

  • Hi,

    SELECT PO_Number, Part_Number

    FROM OrderItem

    WHERE

    (Part_Number=@part_number1 and po_number=@po_number1) or (Part_Number=@part_number2 and po_number=@po_number2) or (Part_Number=@part_number3 and po_number=@po_number3) or (Part_Number=@part_number4 and po_number=@po_number4) or (Part_Number=@part_number5 and po_number=@po_number5)

    --

    -oj

    http://www.rac4sql.com

  • Thanks a lot!!!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply