Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CASE WHEN based on select
Message
 
 
To
13/04/2015 11:55:02
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01618310
Message ID:
01618314
Views:
34
>>
>>WHEN Client.NoCompany>0 THEN
>>
>>case when  (SELECT top (1) Company.Activated FROM Company WHERE Company.Numero=Client.NoCompany)=1 then 2
>>else 3 end
>>end
>
>Thanks, I had this:
>
>
>UPDATE Client
> SET NoType=
>  CASE
>  WHEN Client.NoCompany=0 AND Client.NoProvince>0 THEN 1
>  WHEN Client.NoCompany>0 THEN
>   CASE WHEN EXISTS (SELECT Company.Numero FROM Company WHERE Company.Numero=Client.NoCompany AND Company.Activated=0) THEN 2
>   ELSE 3
>   END
>  END
>
>
>Is this the same thing?

In your case the condition

What has to be adjusted is that if the select has Company.Activated=True, I need to obtain 2. If it is False, I need to obtain 3.

is reversed.

Also, do you have just one row in the company for numero and want to check if it's activated or not? You can change EXISTS to be

(select 1 from Company where Numero = Client.NoCompany and Activated = 0)
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform