Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Modifying one field on multiple records with 3 values
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00487642
Message ID:
00487769
Vues:
12
>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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform