Disregard I believe I got it licked with a LEFT OUTER JOIN.

Thanks
Brad
-----Original Message-----
From: Bradford T Comer [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 21, 2004 4:48 AM
To: SQL
Subject: TSQL Assistance

Can anyone tell me how to use a column from a secondary table in a order by
clause?

----- TBL_A ----
ID int PK NOT NULL
Name Varchar(255)  NULL
SortOrder int DEFAULT(9999) NOT NULL

----- TBL_B ----
ID int PK NOT NULL
Name Varchar(255)  NULL
TBL_A_ID int DEFAULT(0) NOT NULL

---- QUERY ----
SELECT B.*
FROM TBL_B B
WHERE
    ( B.NAME LIKE '%John%' )
        AND
    ( B.TBL_A_ID = TBL_A.ID)
ORDER BY
    TBL_A.SortOrder DESC/ASC

There will be instances where TBL_B will NOT have a record for TBL_A, in
these cases the value of TBL_A_ID will default to 0 - FWIW

I am stumped!

Thanks
Brad
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to