修复下面的脚本。我想跑,并被告知我需要一个连接声明。我如何添加到下面?

时间:2016-08-12 17:44:01

标签: sql

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 个答案:

答案 0 :(得分:0)

您不需要joincase位于select

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;

请注意,在条件工作的情况下,您需要一个列名。这就是??的用途。