Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

order by question

Status
Not open for further replies.

rds80

Programmer
Nov 2, 2006
124
US
Lets say I have a query:

Code:
SELECT N.NoteID,
 CM.DealName
 (SELECT C.FirstName + ' ' + C.LastName
  FROM tblContact C
  INNER JOIN tblSecUser SU
     ON C.ContactID = SU.ContactID_F
  WHERE SU.userid = tblControlMaster.UserID_F) AS Originator
FROM tblControlMaster CM
INNER JOIN tblNote ON CM.ControlID = N.ControlID_F

and now I want to order by C.FirstName and C.LastName. Would I be able to ORDER BY Originator?

Thanks.
 
actually that works, ignore the question above.
 
A quick and dirty way...

Code:
Select NoteId, DealName, Originator
From   (
       SELECT N.NoteID,
        CM.DealName
        (SELECT C.FirstName + ' ' + C.LastName
         FROM tblContact C
         INNER JOIN tblSecUser SU
            ON C.ContactID = SU.ContactID_F
         WHERE SU.userid = tblControlMaster.UserID_F) AS Originator
       FROM tblControlMaster CM
       INNER JOIN tblNote ON CM.ControlID = N.ControlID_F
       ) as A
Order By Originator

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thats pretty cool, George.
Never thought it could be done that way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top