第 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。-Disc (ItemCode) 应该像 G-Disc 但 0-Disc (ItemCode) 应该像 0G-Disc。
我需要选择为
选择版本、项目代码、版本+项目代码....
我已经使用以下内容创建了第三列,但很好奇这是否可以以更好的方式完成......
( 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