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
;
答案 0 :(得分:0)
您不需要join
。 case
位于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;
请注意,在条件工作的情况下,您需要一个列名。这就是??
的用途。