General information
Forum:
Microsoft SQL Server
>I am trying to modify a single field in a table's records that meet specific criteria as follows:
>
>I wish to change, say, Field1 from "THEVALUE" to "THEVALUE-1", "THEVALUE-2" and "THEVALUE-3". I would like to do this in an even 3-way split, i.e. if 3000 records meeting the criterion WHERE Field1 = 'THEVALUE', 1000 records should be set to "THEVALUE-1", another 1000 to "THEVALUE-2", etc.
>
>Your suggestions would be appreciated.
>Thank you.
Use a case statement.
UPDATE mytabe
SET Field1 = CASE field1=thevalue1 WHEN 0 then field1 ELSE thevalue1 end
SET field2 = CASE field2=thevalue2 WHEN 0 then field2 ELSE thevalue2 end
I am not sure I understand what you explained, you say, if field1 = thevalue-1 then set it to thevalue1 ???? Seems unnecessary.
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only