Results 1 to 4 of 4

Thread: Serious SQL Coding Help!!!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    I need to find a way using the table scenario below to remove THE ROWS if the Store_Id and Customer_Id is the same but the Vendor_id is different. (Do not remove if Vendor_ID is the same)using SQl CODE. This list could go on an on in the table with various different number's and stores, etc.


    (identity)
    number_id Store_Id Vendor_Id Customer_Id Quantity
    --------- | --------- | --------- | ----------- | --------
    1 | 100 | 444 | 0 | 100
    2 | 100 | 444 | 0 | 200
    3 | 100 | 555 | 2 | 50
    4 | 200 | 666 | 0 | 125
    5 | 100 | 888 | 0 | 21

    So essentially I would need the remove the last column using in this example using the logic from above.

    I would be sincerely grateful for any guru coding examples/help!!!


  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    I understood your question until you wrote
    So essentially I would need the remove the last column using in this example using the logic from above.

    does this help?

    DELETE *
    FROM Table1
    WHERE ((Store_Id=Customer_Id)And (Store_Id<>Vendor_Id));
    Mark
    -------------------

  3. #3
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    Your description of the problem is very confusing. You say that you want "to remove THE ROWS if the Store_Id and Customer_Id is the same but the Vendor_id is different".

    There are no rows in your table where Store_Id = Customer_Id.

    I think what you are trying to say is:
    when there is more than 1 row with the same Store_Id and Customer_Id, delete any row with a Vendor_id that is different than the rest. So, in the following example, where rows 1, 2, 4 and 5 have Store_Id = 100 and Customer_Id = 0, you would want to delete rows 4 & 5 because Vendor_id <> 444. Is this correct?

    1 | 100 | 444 | 0 | 100
    2 | 100 | 444 | 0 | 200
    3 | 100 | 555 | 2 | 50
    4 | 100 | 666 | 0 | 125
    5 | 100 | 888 | 0 | 21

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    yes exactly!!!!

    thanks for the clarification!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width