update TOP 1

update TOP 1

Post by Hunte » Thu, 29 Aug 2002 23:11:54



Can you use such a query to update only the first of matching records?

Ex.
UPDATE Top 1 ClientName SET FirstName='MeatHead' WHERE ClientID > 0

Thanks,
-Hunter

 
 
 

update TOP 1

Post by Anith Se » Thu, 29 Aug 2002 23:14:38


First, see UPDATE syntax in SQL Server Books Online.
I am not sure which is your tablename, columnname etc.
Here is the guesswork:

Option 1:

SET ROWCOUNT 1
UPDATE ClientName
SET FirstName = 'MeatHead'
WHERE ClientID > 0
SET ROWCOUNT 0

Option 2:

UPDATE ClientName
SET FirstName = 'MeatHead'
WHERE ClientID = (SELECT TOP 1 ClientID
              FROM ClientName)

--
- Anith

 
 
 

update TOP 1

Post by Hunte » Fri, 30 Aug 2002 00:23:14


Thanks anith!  I like option 1 (In case record does not exist.)
-H


Quote:> First, see UPDATE syntax in SQL Server Books Online.
> I am not sure which is your tablename, columnname etc.
> Here is the guesswork:

> Option 1:

> SET ROWCOUNT 1
> UPDATE ClientName
> SET FirstName = 'MeatHead'
> WHERE ClientID > 0
> SET ROWCOUNT 0

> Option 2:

> UPDATE ClientName
> SET FirstName = 'MeatHead'
> WHERE ClientID = (SELECT TOP 1 ClientID
>               FROM ClientName)

> --
> - Anith

 
 
 

1. how to update TOP 15

I want to update a field, but only to the TOP 15.  This is as close as I can
come (which of course does not work):

UPDATE CH_PPC_CC_TRANSACTIONS_COPY_TEMP SET CallID = '187001223125520'
 WHERE callid = (SELECT TOP 15 *
FROM CH_PPC_CC_TRANSACTIONS_COPY_TEMP)

2. Any way to add new records to a combobox grid?

3. Updating TOP X rows ORDERED BY Priority

4. Help with VIEWS

5. Update Top n rows Without Set RowCount

6. Urgent: ODBC32.DLL crashes, why?

7. SELECT TOP & UPDATE

8. UPDATE Query - using Subquery and Top Clause

9. Updating datagrid with requery, datagrid goes to top

10. top 1 is fast, top 2-10 is slow, top 11-81 is semi fast, top 82-1000 is fast.

11. Urgent--Newbie, please Help!:-)--TOP 10 Plus Increments of the next TOP 10