SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 case ? and like?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

marek
Starting Member

Slovakia
34 Posts

Posted - 01/28/2010 :  03:18:13  Show Profile  Reply with Quote
Hallo all
I need help please.

tab1

TOWN
chicago
parisMarseil
vancouverToronto
chicagoLasvegas
paris

result:

tab1

TOWN
usa
france
canada
usa
france

these cities (Chicago,Lasvegas,Marseil, Vancouver, Paris and Toronto
) are always constant cities. I have made the following syntax,to supplement town, but it's wrong. Therefore, please help.
Here is my wrong syntax:

select town from tab1
case (like "%paris%" : "france")
case (like "%lasvegas%" : "usa")
case (like "%marseil%" : "france")
case (like "%chicago%" : "usa")
case (like "%vancouver%" : "canada")
case (like "%toronto%" : "canada")

thanks for help

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 01/28/2010 :  03:44:32  Show Profile  Reply with Quote
is this mapping stored some where?
Go to Top of Page

bklr
Flowing Fount of Yak Knowledge

India
1693 Posts

Posted - 01/28/2010 :  03:44:33  Show Profile  Reply with Quote
SELECT CASE WHEN town LIKE '%chicago%' THEN 'USA'
WHEN town LIKE '%paris%' THEN 'France'
WHEN town LIKE '%lasvegas%' THEN 'usa'
WHEN town LIKE '%marseil%' THEN 'france'
WHEN town LIKE '%vancouver%' THEN 'canada'
WHEN town LIKE '%toronto%' THEN 'canada' END
FROM TABLE
Go to Top of Page

marek
Starting Member

Slovakia
34 Posts

Posted - 01/28/2010 :  03:50:53  Show Profile  Reply with Quote
No, this mapping is not stored some where....

bklr thanks for help
Go to Top of Page

Kristen
Test

United Kingdom
22415 Posts

Posted - 01/28/2010 :  04:16:04  Show Profile  Reply with Quote
" this mapping is not stored some where..."

Have you considered adding a table for that?

Its going to be a pain adding entries to your CASE statement (and it will perform slowly when the list becomes long).

But maybe there are only a few such towns, and they never add more?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 01/28/2010 :  06:27:54  Show Profile  Reply with Quote
quote:
Originally posted by Kristen

" this mapping is not stored some where..."

Have you considered adding a table for that?

Its going to be a pain adding entries to your CASE statement (and it will perform slowly when the list becomes long).

But maybe there are only a few such towns, and they never add more?


I always prefer adding a table for above cases so that I just need to add one more record in case of addition of new town
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000