August 7, 2013 at 5:48 am
I have a script but not in a SQL language:
if ({act_type.act_type_sc} = ["ADD INFO INTERN","ADD INFO P/C"] and instr({act_reg.act_rmk},"closed")>0) then 1
else 0
I was search and i think it was CASE but i dont get a good syntax.. Can somebody helping me out.
Tnx
August 7, 2013 at 5:59 am
This?
SELECT CASE WHEN act_type.act_type_sc = 'ADD INFO INTERN' and instr(act_reg.act_rmk,'closed')>0 then 1
WHEN act_type.act_type_sc = 'ADD INFO P/C' and instr(act_reg.act_rmk,'closed')>0 then 1
else 0 end as colName
from x
August 7, 2013 at 7:47 am
Since instr is a pretty common character index location function I will assume that this is from a programming language.
You could turn this into sql like this:
SELECT CASE
WHEN act_type.act_type_sc IN ('ADD INFO INTERN', 'ADD INFO P/C') AND CHARINDEX('closed', act_reg.act_rmk, 0) > 0 THEN 1
ELSE 0
END AS colName
FROM x
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply