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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need ORDER BY in update

Status
Not open for further replies.

RobHVB6Sql

Programmer
May 20, 2002
77
AU
Update does not allow ORDER BY. How can I select the row with the largest Duration -an integer column?
Code:
SET ROWCOUNT = 1

UPDATE #contacts
SET Prov1ID = cd.IDCode
FROM tblGContactDetails cd
WHERE cd.contactID = #contacts.ContactID
  AND cd.Type = "Provider" 
  ORDER By cd.Duration DESC  -- cant do this!!
--  AND cd.Duration = (SELECT LARGEST(tblGContactDetails.Duration) )

Rob Hasard
(VB6 /SQL 7.0)
 
Code:
UPDATE #contacts
SET Prov1ID = cd.IDCode
FROM tblGContactDetails cd
WHERE cd.contactID = #contacts.ContactID
  AND cd.Type = 'Provider'
  AND cd.Duration = 
   (SELECT max(Duration) 
      from tblGContactDetails)
 
Yep, worked it out. :)
Code:
UPDATE #contacts
SET Prov1ID = cd.IDCode 
FROM tblGContactDetails cd
WHERE cd.contactID = #contacts.ContactID
  AND cd.Type = 'Provider'

  AND cd.Duration = 
   (SELECT MAX(Duration) 
    FROM tblGContactDetails 
    WHERE contactID = #contacts.ContactID 
    AND Type = 'Provider')

Rob Hasard
(VB6 /SQL 7.0)
 
No, sorry I don't.
I'm in Perth - Western Australia.
Probably a long way from most of you guys and gals. :)

Rob Hasard
(VB6 /SQL 7.0)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top