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

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.