在下面的select语句中,当@PAPCOD = 'SIN‘=值是'DD’和'SD‘以及@PAPCOD = 'ENG’=值是'DI‘和'SI’时,我想放入两个值
我该怎么做呢。只有一个值可以
SELECT ISNULL((SUM(Con_Amount)),0) +
(SELECT DISTINCT ISNULL(SUM(Correspondent_Other_Payments.Oth_Pmt_Amount),0)
FROM Correspondent_Other_Payments
WHERE Correspondent_Other_Payments.Oth_Cnt_Code = Contributions.Con_Cnt_Code and
Correspondent_Other_Payments.Oth_Prv_Code = Contributions.Con_Prv_Code and
Correspondent_Other_Payments.Oth_Dst_Code = Contributions.Con_Dst_Code and
Correspondent_Other_Payments.Oth_Cor_Code = Contributions.Con_Cor_Code and
Correspondent_Other_Payments.Oth_Pmt_Date = CONVERT(DATE, @PubDatE, 111) and
Correspondent_Other_Payments.Oth_AuditChk = 'Y')
FROM Contributions
INNER JOIN Correspondent_Master
ON Contributions.Con_Cnt_Code = Correspondent_Master.Cor_Country_Code and
Contributions.Con_Prv_Code = Correspondent_Master.Cor_Province_Code and
Contributions.Con_Dst_Code = Correspondent_Master.Cor_District_Code and
Contributions.Con_Cor_Code = Correspondent_Master.Cor_Code
WHERE Con_paper LIKE
CASE
WHEN @PapCod = 'SIN' THEN
'DD'
WHEN @PapCod = 'ENG' THEN
'DI'
ELSE
@PapCod
END and
(Con_PubDate BETWEEN CONVERT(DATE, @PubDatB, 111) and
CONVERT(DATE, @PubDatE, 111)) and
Contributions.Audit_Chk = 'Y' /* Audited */
GROUP BY Contributions.Con_Cnt_Code,
Contributions.Con_Prv_Code,
Contributions.Con_Dst_Code,
Contributions.Con_Cor_Code,
Contributions.Con_Paper
ORDER BY Contributions.Con_Cnt_Code,
Contributions.Con_Prv_Code,
Contributions.Con_Dst_Code,
Contributions.Con_Cor_Code

发布于 2018-10-09 16:26:39
只需添加一个OR,复制相同的情况,并将值更改为SD和SI。
DECLARE
@t TABLE(Con_Paper VARCHAR(50), Con_Amount INT)
INSERT INTO @t VALUES
('DD', 100)
,('SD', 250)
,('BN',450)
,('DD',50)
,('DI',350)
,('NL',65)
DECLARE @PapCod VARCHAR(50) = 'ENG'
SELECT SUM(Con_Amount)
FROM @t
WHERE
(Con_paper LIKE
CASE
WHEN @PapCod = 'SIN' THEN 'DD'
WHEN @PapCod = 'ENG' THEN 'DI'
ELSE @PapCod
END
OR
Con_paper LIKE
CASE
WHEN @PapCod = 'SIN' THEN 'SD'
WHEN @PapCod = 'ENG' THEN 'SI'
ELSE @PapCod
END
) https://stackoverflow.com/questions/52716131
复制相似问题