Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my query is below

case when Business_Group like '%Back Office%' then bonus as Support else bonus end as ALC
Posted

Although your question is not clear, the error in you query was unwanted "as Support" in between the case when statement.
syntactically corrected query is-
SQL
case when Business_Group like '%Back Office%' then bonus else bonus end as ALC


But this is something you never want as result, what I believe. Your logic should be
--if Business_Group contains text like 'Back Office' then return bonus in result as ALC
--if not then return different result for result column ALC

Make sure that you understand "case when..." correctly.
Reference: CASE in SQL Server[^]

Hope, it helps :)

UPDATE
As per the comment by OP, the solution query should look like-
SQL
select case when Business_Group like '%Back Office%' then bonus else NULL end as Support,case when Business_Group like '%Back Office%' then NULL else bonus end as ALC


I beleive there can be a better way to do this but as you wanted the solution using "case when..", this can help.

Please let me know if it doesn't help.
 
Share this answer
 
v2
Comments
neeraj_ 21-Jul-15 6:13am    
sir actually bonus is a column
i want to divide thats value in two columns according bussiness_group
Suvendu Shekhar Giri 21-Jul-15 6:58am    
Please check the updated solution.
neeraj_ 21-Jul-15 7:34am    
a lot of thanks sir
its worked properly
Suvendu Shekhar Giri 21-Jul-15 8:07am    
Glad to know that it helped :)
See this : http://stackoverflow.com/a/6740207[^]

Regards..
 
Share this answer
 
Comments
neeraj_ 21-Jul-15 5:56am    
sir i want an other column's value instead of like column

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900