May 22, 2007 at 12:59 pm
Hey guys how can i use the "like" in a Case statement?
thx much
May 22, 2007 at 1:01 pm
Can you provide an example of what you are trying to do and include sample data and results?
May 22, 2007 at 1:04 pm
just want sripts man
Select
Case when find_This = Like '%Pleasehelpme' else 'u_Can't' end as [Can You]
etc
May 22, 2007 at 1:18 pm
I'm still not exactly sure what you're after but here you go:
DECLARE @table TABLE (value varchar(100))
INSERT INTO @table
SELECT 'Please help me because I cant help myself' UNION ALL
SELECT 'u cant help me because my example stinks'
SELECT
CASE WHEN value LIKE 'Please help me%' THEN value END AS 'Yes, I can',
CASE WHEN value LIKE 'u cant%' THEN value END AS 'No, I cannot'
FROM @table
beware of using LIKE '%value' as it will cause table scans!
May 22, 2007 at 1:21 pm
Yes, your syntax is incorrect in your example. The question, if not answered by the above, is "What is your goal"?
May 22, 2007 at 1:21 pm
LOL.... great answer man ur a genious
May 23, 2007 at 9:12 am
Hi,
Yes you can use Like with Case
Shabbir Muntakhab
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply