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

update tablename set col1='newvalue' where col2='my condition'

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

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

Cheers.

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

Member Avatar for Branasinflake

update top(10) MyTable set MyColumn = 22

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.