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 |
|
sql777
Constraint Violating Yak Guru
314 Posts |
Posted - 2008-07-12 : 15:43:13
|
| Hi,I need to do something like:SELECT category = CASE url WHEN like 'www.example.com/articles/%' THEN 'articles' WHEN like 'www.example.com/forums/%' THEN 'forums' ELSE '' ENDFROM contentHow can I achieve this? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-07-12 : 15:45:27
|
Try this:SELECT category = CASE WHEN url LIKE '...%' THEN 'articles' WHEN url LIKE '...%' THEN 'forums' ELSE '' ENDFROM content Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
sql777
Constraint Violating Yak Guru
314 Posts |
Posted - 2008-07-12 : 17:22:23
|
| Thanks!I was doing:select category = case URL WHEN url like. ...case URL was causing the error! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-14 : 03:28:45
|
quote: Originally posted by sql777 Thanks!I was doing:select category = case URL WHEN url like. ...case URL was causing the error!
Note that the CASE expression you used is simple CASE which can be used to test for equality only. Otherwise you need to use searched CASE which can be used for any comparisonThats why I always suggest to useCASE when expression... thanCASE expression whenMadhivananFailing to plan is Planning to fail |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-14 : 03:48:26
|
Which is very well explained in Books Online. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|
|