tags:

views:

429

answers:

4

I am trying to figure out how to select half the records where an ID is null. I want half because I am going to use that result set to update another ID field. Then I am going to update the rest with another value for that ID field.

So essentially I want to update half the records someFieldID with one number and the rest with another number splitting the update basically between two values for someFieldID the field I want to update.

+3  A: 

In oracle you can use the ROWNUM psuedocolumn. I believe in sql server you can use TOP (e.g., select TOP 50 PERCENT * from table)

Arnshea
Is there sort of a bottom 50 percent? such as lets say you have 100 records, bottom would be last 50?
CoffeeAddict
Use the Order by clause
Jhonny D. Cano -Leftware-
+1  A: 

You can select by percent:

 SELECT TOP 50 PERCENT *fields* FROM YourTable WHERE ...
Dana
+2  A: 

update x set id=@value from (select top 50 percent * from table where id is null) x

Hafthor
A: 
Ryan