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.
| 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 be1-S1111 would be Stainless1-C1111 would be CarbonBelow 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 MetalFROM 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. |
 |
|
|
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. |
 |
|
|
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 metalFROM Valve_Table[/code]Fred is fast |
 |
|
|
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. |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-01-18 : 17:18:42
|
| LOL |
 |
|
|
reviewdood
Starting Member
2 Posts |
Posted - 2010-01-25 : 14:49:52
|
| Thank you Very Much!!! |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
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. |
 |
|
|
|
|
|