我有一张像这样的桌子
UniqID |Part |Name
---------|-----------------|----------------------------------------------
1 |StickerForm |C:\Muscateers\SummaryLabel.dotm
2 |InvoiceForm |\\online-storage\secure\MMCC Invoice Layout.dotm
3 |RepairForm |\\online-storage\secure\MMCC Repair Layout.dotm
4 |Receip Label |\\online-storage\secure\ReceiptLabel.dotm
5 |InvoiceSavePath |\\online-storage\secure\Invoices\
6 |RepairSavePath |\\online-storage\secure\Repairs\
7 |ReportPrinter |HP LaserJet P2050 Series PCL6
8 |ReceiptPrinter |EPSON TM-T88IV Receipt
9 |StickerPrinter |Brother QL-810W我想从1个结果中的UniqID 3、6、7中检索name列,即
\\online-storage\secure\MMCC Repair Layout.dotm \\online-storage\secure\Repairs\ HP LaserJet P2050 Series PCL6这有可能吗?如果是这样的话,你能给我看一个代码样本吗?
发布于 2020-01-04 12:08:10
大多数答案是使用Coalesce或类似的,我不希望我在尝试了4天后终于得到了我想要的东西
Create table #myrow
(eForm varchar(65) ,
ePath varchar(65) ,
ePrint varchar(65))
Create table #Temp
( UniqID int,
Name Varchar(65))
Insert into #Temp
SELECT * FROM (SELECT [Uniqid],[Name] FROM [dbo].[PathForms]
where UniqID in (3,6,7))src
Insert into #myrow
SELECT * FROM #Temp
PIVOT (MAX([Name]) FOR [UniqID] in ([3] , [6] , [7] )) as pvt
Drop table #Temp
Select
eForm, ISNULL(ePath,'') as ePath ,ePrint from #myrow
Drop table #myrowhttps://stackoverflow.com/questions/59587792
复制相似问题