CREATE TABLE #tp
(
headerNo VARCHAR(10),
machineNO VARCHAR(10),
descrption nVARCHAR(20),
artNo VARCHAR(20),
qty INT ,
repartno varchar(20) ,
repqty INT
)
insert INTO #tp SELECT 'HD01','0101520',N'电池出问题','102020',2,'102020',2
insert INTO #tp SELECT 'HD01','0101520',N'电池出问题','101010',2,'202020',2
insert INTO #tp SELECT 'HD01','0101520',N'电池出问题','126888',2,'102020',2
insert INTO #tp SELECT 'HD02','01012221',N'D电机故障','102020',2,'102020',2
insert INTO #tp SELECT 'HD03','12312312',N'突然停机','102020',2,'102020',2
insert INTO #tp SELECT 'HD03','12312312',N'突然停机','102020',2,'102020',2
insert INTO #tp SELECT 'HD04','12312344',N'皮带松了','102020',2,'102020',2
SELECT CASE when row=1 THEN headerNo ELSE '' END headerNo,
CASE when row=1 THEN machineNO ELSE '' END machineNO,
CASE when row=1 THEN descrption ELSE '' END descrption
,artNo,qty,repartno,repqty
FROM
(
SELECT *,row_number()OVER(PARTITION BY headerNo,machineNO,descrption ORDER BY GETDATE())row
FROM #tp
)M
手机扫一扫
移动阅读更方便
你可能感兴趣的文章