列 1:
( CASE
WHEN (SELECT edition
FROM clients.dbo.service
WHERE serv_id = hdr.serv_id) = 'General' THEN 'G'
WHEN (SELECT edition
FROM clients.dbo.service
WHERE serv_id = hdr.serv_id) = 'Honors' THEN 'H'
WHEN (SELECT edition
FROM clients.dbo.service
WHERE serv_id = hdr.serv_id) = 'WhosWho' THEN 'Y'
WHEN (SELECT edition
FROM clients.dbo.service
WHERE serv_id = hdr.serv_id) = 'Catholic' THEN 'J'
WHEN (SELECT edition
FROM clients.dbo.service
WHERE serv_id = hdr.serv_id) = 'Conservative' THEN 'B'
ELSE 'H'
END ) AS Edition
列 2:
(SELECT edition
FROM clients.dbo.service
WHERE serv_id = hdr.serv_id) AS editiontext,
( CASE
WHEN hdr.giftcarddiscount = 1 THEN 'GCDisc'
ELSE ( CASE
WHEN si.itmclass = 'Distrib' THEN '-Disc'
WHEN si.itmclass = 'PremIR' THEN '0' + '-Disc'
WHEN si.itmclass = 'InstResp' THEN '5' + '-Disc'
ELSE ''
END )
END ) AS 'ItemCode'
Edition と ItemCode の両方を 3 列目に組み合わせる必要があります。-Disc (ItemCode) は G-Disc のようにする必要がありますが、0-Disc (ItemCode) は 0G-Disc のようにする必要があります。
次のように選択する必要があります
Edition、ItemCode、Edition+ItemCode... を選択します。
私は以下を使用して 3 番目の列を作成しましたが、これをより良い方法で行うことができるかどうか興味があります...
( CASE
WHEN (SELECT edition
FROM clients.dbo.service
WHERE serv_id = hdr.serv_id) = 'General' THEN (
CASE
WHEN hdr.giftcarddiscount = 1 THEN 'GCDisc'
ELSE( CASE
WHEN si.itmclass = 'Distrib' THEN 'G-Disc'
WHEN si.itmclass = 'PremIR' THEN '0G' + '-Disc'
WHEN si.itmclass = 'InstResp' THEN '5G' + '-Disc'
ELSE ''
END )
END )
WHEN (SELECT edition
FROM clients.dbo.service
WHERE serv_id = hdr.serv_id) = 'Honors' THEN (
CASE
WHEN hdr.giftcarddiscount = 1 THEN 'GCDisc'
ELSE( CASE
WHEN si.itmclass = 'Distrib' THEN 'H-Disc'
WHEN si.itmclass = 'PremIR' THEN '0H' + '-Disc'
WHEN si.itmclass = 'InstResp' THEN '5H' + '-Disc'
ELSE ''
END )
END )
WHEN (SELECT edition
FROM clients.dbo.service
WHERE serv_id = hdr.serv_id) = 'WhosWho' THEN (
CASE
WHEN hdr.giftcarddiscount = 1 THEN 'GCDisc'
ELSE( CASE
WHEN si.itmclass = 'Distrib' THEN 'Y-Disc'
WHEN si.itmclass = 'PremIR' THEN '0Y' + '-Disc'
WHEN si.itmclass = 'InstResp' THEN '5Y' + '-Disc'
ELSE ''
END )
END )
WHEN (SELECT edition
FROM clients.dbo.service
WHERE serv_id = hdr.serv_id) = 'Catholic' THEN (
CASE
WHEN hdr.giftcarddiscount = 1 THEN 'GCDisc'
ELSE( CASE
WHEN si.itmclass = 'Distrib' THEN 'J-Disc'
WHEN si.itmclass = 'PremIR' THEN '0J' + '-Disc'
WHEN si.itmclass = 'InstResp' THEN '5J' + '-Disc'
ELSE ''
END )
END )
WHEN (SELECT edition
FROM clients.dbo.service
WHERE serv_id = hdr.serv_id) = 'Conservative' THEN (
CASE
WHEN hdr.giftcarddiscount = 1 THEN 'GCDisc'
ELSE( CASE
WHEN si.itmclass = 'Distrib' THEN 'B-Disc'
WHEN si.itmclass = 'PremIR' THEN '0B' + '-Disc'
WHEN si.itmclass = 'InstResp' THEN '5B' + '-Disc'
ELSE ''
END )
END )
ELSE ( CASE
WHEN hdr.giftcarddiscount = 1 THEN 'GCDisc'
ELSE( CASE
WHEN si.itmclass = 'Distrib' THEN 'H-Disc'
WHEN si.itmclass = 'PremIR' THEN '0H' + '-Disc'
WHEN si.itmclass = 'InstResp' THEN '5H' + '-Disc'
ELSE ''
END )
END )
END ) AS EditionItemCode