SQL Server CASE WHEN ... THEN ... ELSE ... END

侬侬发發表於2024-07-25
SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_no='LJCG001H' THEN  dbo.ELTPNAME(a.fw_nu) ELSE  d.fm_name END),e.fw_state_nm,f.fw_rmk_nm 

FROM LJSS007H a (nolock)

left join LJPA003H b (nolock) on a.dp_no=b.dp_no

left join LJPA001H c (nolock) on c.pa_no=a.pa_no1

left join LJSS002H d (nolock) on d.fm_no=a.fm_no

left join LJSS008H e (nolock) on a.fw_state=e.fw_state_no

left join LJSS009H f (nolock) on a.fw_rmk_no=f.fw_rmk_no

WHERE a.fw_state>=2 And a.pa_no ='A0202002' and a.cr_time>='2024-07-01 00:00:00' and a.cr_time<='2024-07-19 23:59:59'

相關文章