感谢您一直以来的帮助。这是上一个线程的延续。
我想要做的是替换结果字段之一(比如说PROJECT_ID)中的值来做这样的事情。我希望这很简单。但这个项目还有更多。
select oc.ncr_no,
max(case when OC.LU_NAME = 'Project' then OC.KEY_REF end) PROJECT_ID,
max(case when OC.LU_NAME = 'SupplierInfo' then OC.KEY_REF end) SUPPLIER_ID,
max(case when OC.LU_NAME = 'PurchaseOrder' then OC.KEY_REF end) ORDER_NO,
max(case when OC.LU_NAME = 'PurchaseReceipt' then OC.KEY_REF end) PURCHASE_RECEIPT,
max(case when OC.LU_NAME = 'InventoryPart' then OC.KEY_REF end) INVENTORY_PART,
replace(PROJECT_ID,'PROJECT_ID=','') as PROJECT_ID
from OC
group by oc.ncr_no
我在示例中使用了这个模式(从 SQL Fiddle 中提取)。不幸的是,我不知道如何保存它。
CREATE TABLE OC
(
[NCR_NO] int,
[LU_NAME] varchar(15),
[KEY_REF] varchar(33)
);
INSERT INTO OC ([NCR_NO], [LU_NAME], [KEY_REF])
VALUES
(100001, 'Project', 'PROJECT_ID=PROJECT1^'),
(100001, 'SupplierInfo', 'SUPPLIER_ID=UNIQUESUPPLIERNUMBER^'),
(100001, 'PurchaseOrder', 'ORDER_NO=UNIQUEORDERNO^'),
(100196, 'PurchaseReceipt', 'UNIQUE PURCHASE RECEIPT'),
(100511, 'InventoryPart', 'CONTRACT=UNIQUECONTRACTNO');