User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 423,532 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,340 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 654 | Replies: 1
Reply
Join Date: Feb 2008
Posts: 2
Reputation: linker3000 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
linker3000 linker3000 is offline Offline
Newbie Poster

Wildcards in CASE statements

  #1  
Feb 29th, 2008
Hi Folks,

Just a quickie - can wildcards be used in CASE statements? I have inherited some code and wondered if this:

(case substring(anownedby,0,charindex('/',anownedby))
   when '2361' then 'GOD' when '2361c' then 'GOD' when '2361d' then 'GOD' 
   when '6206252' then 'BIL' when 'bil' then 'BIL' else 'XXX' end) as branch

could be replaced with this:

(case substring(anownedby,0,charindex('/',anownedby))
   when '2361%' then 'GOD' when '6206252' then 'BIL' when 'bil' then 'BIL' else 'XXX' end) as branch

Thanks

L3K
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2008
Posts: 2
Reputation: linker3000 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
linker3000 linker3000 is offline Offline
Newbie Poster

Re: Wildcards in CASE statements

  #2  
Feb 29th, 2008
Just another thought, rather than taking a substring first, would something like the following be faster or will the 'like's hit performance worse:

case 
     when anownedby like '2968%' then 'RUS'
     when anownedby like '1997%' then 'LEW'
     ... 28 more 'whens'...
     else 'XXX' end as branch

Ta!
Last edited by linker3000 : Feb 29th, 2008 at 10:06 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 5:25 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC