954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Update n number of rows

Hi,

I have 20 rows in a table and I want to update 10 of them only.

I am using MS SQL.

Any ideas please.

Cheers

Red_Indian
Light Poster
27 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 
update tablename set col1='newvalue' where col2='my condition'
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
 

use below procedure
---------------------------


USE testtable;
GO
UPDATE testtable.Employee
SET salary=salary+1000
WHERE Sal>=5000 and sal<=15000
IF @@ROWCOUNT = 10
PRINT 'Count limit is reached.';
GO

rickymartin3
Newbie Poster
9 posts since May 2010
Reputation Points: 10
Solved Threads: 3
 

Thanks for the suggestion.

There are 3 columns. But as you know the very first column is nameless and numbers each row. I cannot use a any of the columns to set a condition e.g. if col1 < 'value1' and > 'value2'. I just want to be able to update 2 columns values up to 10 rows.

Hope that makes sense.

Thanks for the help

Red_Indian
Light Poster
27 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

Cheers.

Can you use the IF @@ROWCOUNT = 10 without the WHERE condition?

Red_Indian
Light Poster
27 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

update top(10) MyTable set MyColumn = 22

Branasinflake
Newbie Poster
1 post since Jul 2011
Reputation Points: 10
Solved Threads: 1
 

Update EMPLOYEE set EMPNAME='SomeValue' where EMPID in(1,2,3,4,5,6,7,8,9,10)

prit005
Light Poster
39 posts since Jul 2011
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You