2016-08-12 8 views
-1
declare @s varchar(100)='(FILE'; 
select clientid 
     ,ClientSort as ClientName 
     ,'Y' as Enabled 
     ,'N' as HIPPA 
     ,matternum 
     ,case 
      when charindex(@s,[description])>0 
      then left(cast([description] as varchar(max)),charindex(@s,[description])-1) 
      else [description] 
     end as MatterName 
     ,'Y' as Enable 
     ,'N' as HIPPA 
,Status 
    from matters 
SELECT 
CASE 
WHEN 'Family Law' then 'FL' 
WHEN 'Workers Comp' then 'WC' 
WHEN 'Criminal' then 'CR' 
WHEN 'Corporate Business' then 'CB' 
WHEN 'Personal Injury' then 'PI' 
WHEN 'Litigation' then 'LI' 
WHEN 'Estate Matters' then 'EM' 
WHEN 'Miscellaneous' then 'MI' 
WHEN 'Appeals' then 'AP' 
WHEN 'Real Estate' then 'RE' 
END as areaoflaw 
order by Clientid 
     ,matterid 
; 
+1

あなたは 'JOIN'が必要だと知っていますが、あなたはそれをやる方法を研究しましたか? – Nicarus

+0

また、最後の 'CASE'ステートメントは、値の列を参照していないので意味がありません... – Nicarus

答えて

0

joinは必要ありません。 caseselectに行く:あなたは条件が機能する場合の後、列名が必要

SELECT . . ., 
     CASE ?? 
      WHEN 'Family Law' then 'FL' 
      WHEN 'Workers Comp' then 'WC' 
      WHEN 'Criminal' then 'CR' 
      WHEN 'Corporate Business' then 'CB' 
      WHEN 'Personal Injury' then 'PI' 
      WHEN 'Litigation' then 'LI' 
      WHEN 'Estate Matters' then 'EM' 
      WHEN 'Miscellaneous' then 'MI' 
      WHEN 'Appeals' then 'AP' 
      WHEN 'Real Estate' then 'RE' 
     END as areaoflaw 
from matters 
order by Clientid; 

注意。それが??の目的です。

+0

そのcase文は間違っています。うまくいかないだろう。 – Nicarus

+0

@Nicarus。 。 。ありがとうございました。私は今それに取り組んでいます。 –

+0

ありがとうございました。 – GrizzleBear

関連する問題