Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Modifying one field on multiple records with 3 values
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00487642
Message ID:
00487769
Views:
11
>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
Map
View

Click here to load this message in the networking platform