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

Running an update for 50% of records

Status
Not open for further replies.

mpramods

Technical User
Jun 3, 2003
50
US
I need to update the value in a column for 50% of the records in the table. I need to use a single sql for this. I am using the following but it does not work.

update a
set column_name = 'xxxxx'
where acct in
(
sel acct from a
sample .50
)

It fails with a message saying that I cannot use sample in a subquery.

Does anybody know of a way to do this?

Thanks,
Pramod
 
Hi,

Here is what i tried to update 50% of the records in a table. Hope this helps.

create table test123 (acct integer, b integer);
insert into test123 values(1,NULL);
insert into test123 values(2,NULL);
insert into test123 values(3,NULL);
insert into test123 values(4,NULL);

update test123
from
(select acct from test123 sample .50) as b
set b = 1
where test123.acct = b.acct


select * from test123;
acct b
------- ------
2 (null)
4 1
1 (null)
3 1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top