本文介紹了將多個布爾列合并為一列的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在從一個 ERP 系統生成報告,其中為用戶提供了一個復選框,該復選框為所選的每個項目返回一個布爾值.數據庫托管在 SQL Server 上.
I am generation reports from an ERP system where users are provided with a check box which return a boolean value for each item selected. The database is hosted on SQL Server.
但是,用戶也可以選擇具有其他值的合同,如下所示.
However, users can select Contracts with other values as well, as shown below.
我想將類別捕獲為單列,并且我不介意視圖中有重復的行.對于相同的參考 ID,我希望第一行返回 Contract,第二行返回選擇的其他值.
I would like to capture the Categories as a single column and I don't mind having duplicate rows in the view. I would like the first row to return Contract and the second the other value selected, for the same Reference ID.
推薦答案
您可以使用 apply
:
select distinct t.*, tt.category
from t cross apply
( values ('Contracts', t.Contracts),
('Tender', t.Tender),
('Waiver', t.Waiver),
('Quotation', t.Quotation)
) tt(category, flag)
where flag = 1;
這篇關于將多個布爾列合并為一列的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!