Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Case with multiple then
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01047563
Message ID:
01047564
Vues:
7
The CASE is a function that returns value - one value. If you want to do more than that, use IF
IF (@state = 'CA' or @state = 'WA' or @state = 'OR') and @plinid = 'PERDOM' 
BEGIN
  set @result = 1
  -- Do something 
END
ELSE IF (@state = 'NY') and (@comcode = 'KR') and (@plinid <> 'DJAR' AND @plinid <> 'DREAMS') and (@item not like '%LIP_%')
BEGIN
  set @result = 2
  -- Do something 
END
ELSE
BEGIN
  set @result = 999
  -- Do something 
END
>set @result =
>case
>
>when (@state = 'CA' or @state = 'WA' or @state = 'OR') and @plinid = 'PERDOM' then 0 "--set @reson = 'PERDOM product line not allowed in CA,WA, OR'"
>
>when (@state = 'NY') and (@comcode = 'KR') and (@plinid <> 'DJAR' or @plinid <> 'DREAMS') and (@item not like '%LIP_%') then 0
>
>else 1
>end
>
>I want to be able to set @result to 0 or 1, which works fine, but I also want to set another variable, for example
>
>when this then 1 and 2
>
>Not sure if I can do this. Any help would be appreciated, thanks!!!
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform