Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Case in Where clause
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01303803
Message ID:
01303807
Vues:
11
If it has to be done in one UPDATE
update mytable
 SET fieldx = NULL,
 	field1 = CASE WHEN @MyFlag = 'Y' THEN somevalue ELSE field1 END, 
 	field2 = CASE WHEN @MyFlag <> 'Y' THEN someothervalue ELSE field2 END
Otherwise
update mytable
 SET fieldx = NULL
update mytable field1 = somevalue
	WHERE @MyFlag = 'Y' 
update mytable field2 = someothervalue
	WHERE @MyFlag <> 'Y' 
>Hi all, is it possible to use a Case statement in a Where clause ?, what I am trying to do , is , update a table using either field1 = somevalue or field2 = someothervalue depending on a flag setting
>
>
>
>pseudo babble
>
>update mytable
>set fieldx = null
>Where
>If @MyFlag = 'Y'
>field1 = somevalue
>else
>field2 = someothervalue
>
>
>
>hope that makes sense
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform