Query Help

  • I need some assistance. I appear to be having a brain fart at the moment and just can't seem to get the results I'm looking for. Here's my basic dilema:

    I've got 2 tables in a SQL 2000 Database, ARDoc and Shippers... Both tables have a common order number field (OrdNbr) as well as Invoices (InvcNbr in Shippers and RefNbr in ARDoc). In some cases, the invoices between the 2 tables do not match. I need to be able to get a result set for the order numbers that do not have matching Invoice numbers. Any assistance is greatly appreciated.

  • Select ARDoc.OrdNbr from ARDoc

    left outer join Shippers

    on ARDoc.OrdNbr = Shippers.OrdNbr

    where Shippers.InvcNbr ARDoc.RefNbr

    The Users are always right - when I'm not wrong!

  • Just making it cleaner:

    Select ARDoc.OrdNbr from ARDoc

    left outer join Shippers on ltrim(rtrim(ARDoc.OrdNbr)) = ltrim(rtrim(Shippers.OrdNbr))

    where isnull(ltrim(rtrim(Shippers.InvcNbr)),'') <> isnull(ltrim(rtrim(ARDoc.RefNbr)),'')

  • Yes, it makes more sense to use the trim functions when you have the columns that allow even the character datatypes.


    Prasad Bhogadi

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

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