Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Can IF THEN statements contain Wildcards?

Author  Topic 

reviewdood
Starting Member

2 Posts

Posted - 2010-01-18 : 15:29:09
I have an IF THEN statement that looks at a number. A character in that number determins the material it is made from. I am trying to have the IF THEN statement look at that character and spit out just what material it is made of. The table contains all the proper information but I just recieve NULL as my result. An example would be
1-S1111 would be Stainless
1-C1111 would be Carbon
Below is what I have so far. I know it is wrong I am just wondering if i'm even close to the result i'm looking for.

SELECT TOP (100) PERCENT CASE ITEM_TYPE WHEN '_-C%' THEN 'Carbon' WHEN '_-S%' THEN 'Stainless' END AS Metal
FROM Valve_Table

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-18 : 16:59:26
CASE
WHEN ITEM_TYPE LIKE '_-C%' THEN 'CARBON'
WHEN ITEM_TYPE LIKE '_-S%' THEN 'Stainless'
END as Metal


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-18 : 17:00:15
But maybe you need an ELSE to if there are more than C and S...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-01-18 : 17:00:42
[code]SELECT Case
WHEN item like '_-C%' THEN 'Carbon'
WHEN item like '_S%' THEN 'Stainless'
...
End as metal
FROM Valve_Table[/code]

Fred is fast
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-18 : 17:14:50
fast?
yes I get tired fast


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-01-18 : 17:18:42
LOL
Go to Top of Page

reviewdood
Starting Member

2 Posts

Posted - 2010-01-25 : 14:49:52
Thank you Very Much!!!
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-01-25 : 14:54:28
quote:
Originally posted by webfred

fast?
yes I get tired fast


No, you're never too old to Yak'n'Roll if you're too young to die.



Your wife must not be happy...you need some of that fresh beer with all the B12 from the yeast



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-26 : 01:18:44
That is maybe the problem - I hate yeast


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -