1

有什么方法可以将以下内容和 set @FH_RecordKeyand组合@VF_dept_seq在一个SETorSELECT语句中?

    set @FH_RecordKey =(
        case @lnktble
            when 'ems' then (select FH_inci_id from FH_Catherine_live.dbo.FH_MAP_EMS_INCI where VF_ems_seq = @tempseq)
            when 'imaster' then (select FH_insp_id from FH_Catherine_live.dbo.FH_MAP_INSPID where VF_in_seq = @tempseq)
            when 'n5basic' then (select inci_id from [dbo].[VF_IncWorkTable] where inc_seq = @tempseq)
        END)


    set @VF_dept_seq = (
        case @lnktble
            when 'ems' then (select VF_dept_seq from FH_Catherine_Live.dbo.FH_MAP_EMS_INCI where VF_ems_seq = @tempseq)
            when 'imaster' then (select VF_dept_seq from FH_Catherine_Live.dbo.FH_MAP_INSPID where VF_in_seq = @tempseq)
            when 'n5basic' then (select dept_seq from [dbo].[VF_IncWorkTable] where inc_seq = @tempseq)
        end)
4

2 回答 2

1

使用IF语句而不是CASE

IF @lnktble = 'ems'
select  @FH_RecordKey = FH_inci_id ,@VF_dept_seq = VF_dept_seq
from FH_Catherine_live.dbo.FH_MAP_EMS_INCI 
where VF_ems_seq = @tempseq
ELSE IF @lnktble = 'imaster' /*...*/
于 2012-06-27T13:08:25.580 回答
0
Select @FH_RecordKey = 
  (case statement here),
@VF_dept_seq = 
  (case statement here)
于 2012-06-27T12:30:19.610 回答