Hallo, ich habe eine SQL View (Server 2012) in der ich mehrere Tabellen verknüpfe.
In der Change Log Tabelle sind mehrere Zeilen (LogText) pro Zeichnungsnummer (DrawNum). Wenn ich die Query so ausführe kriege ich leider mehrere Zeilen pro Zeichnunsnummer ausgegeben, pro ChangeLog Eintrag eine Zeile. Ist es möglich die ChangeLog Einträge irgendwie zusammenzufassen, dass ich pro Zeichnung nur noch eine Zeile habe und die verschiedenen ChangeLog Einträge in einer Zelle zusammengefasst sind? Hier die Syntax meiner View:
SELECT Erp.ProjPhase.ProjectID, Erp.ProjPhase_UD.MachineID_c AS EquipmentID, Erp.ProjPhase_UD.Machine_c AS Equipment, Erp.JobAsmbl.JobNum AS JobID, Erp.ProjPhase.Description AS JobDescription, Erp.JobAsmbl.AssemblySeq AS AssemblyID, Erp.JobAsmbl.Description AS [Assembly Description], Erp.JobAsmbl.DrawNum AS Drawing, Erp.JobAsmbl.RevisionNum AS [Drawing Rev], Erp.JobAsmbl.RequiredQty AS Quantity, Erp.JobAsmbl.CommentText AS Comment, (CASE WHEN SUM(CASE WHEN JobMtl_UD.IsShippingItem_c = 'TRUE' THEN JobMtl_UD.TotalWeight_c ELSE 0 END) = 0 THEN SUM(CASE WHEN JobMtl_UD.IsPreAssembly_c = 'TRUE' THEN JobMtl_UD.TotalWeight_c ELSE 0 END) ELSE SUM(CASE WHEN JobMtl_UD.IsShippingItem_c = 'TRUE' THEN JobMtl_UD.TotalWeight_c ELSE 0 END) END) AS [Weight/Asm], (CASE WHEN SUM(CASE WHEN JobMtl_UD.IsShippingItem_c = 1 THEN JobMtl_UD.TotalWeight_c ELSE 0 END) * JobAsmbl.RequiredQty = 0 THEN SUM(CASE WHEN JobMtl_UD.IsPreAssembly_c = 1 THEN JobMtl_UD.TotalWeight_c ELSE 0 END) * JobAsmbl.RequiredQty ELSE SUM(CASE WHEN JobMtl_UD.IsShippingItem_c = 1 THEN JobMtl_UD.TotalWeight_c ELSE 0 END) * JobAsmbl.RequiredQty END) AS [Total Weight], (CASE WHEN SUM(CASE WHEN JobMtl_UD.IsShippingItem_c = 1 AND JobMtl_UD.FabricationPart_c = 1 THEN JobMtl_UD.TotalWeight_c ELSE 0 END) = 0 THEN SUM(CASE WHEN JobMtl_UD.IsPreAssembly_c = 1 AND JobMtl_UD.FabricationPart_c = 1 THEN JobMtl_UD.TotalWeight_c ELSE 0 END) ELSE SUM(CASE WHEN JobMtl_UD.IsShippingItem_c = 1 AND JobMtl_UD.FabricationPart_c = 1 THEN JobMtl_UD.TotalWeight_c ELSE 0 END) END) * Erp.JobAsmbl.RequiredQty AS [Total FabWeight], CAST(Ice.ChgLog.DateStampedOn AS datetime) AS [Last Rev Date], Ice.ChgLog.LogText AS [Rev Comment]
FROM Ice.ChgLog RIGHT OUTER JOIN
Erp.JobHead INNER JOIN
Erp.JobAsmbl_UD INNER JOIN
Erp.JobAsmbl ON Erp.JobAsmbl_UD.ForeignSysRowID = Erp.JobAsmbl.SysRowID ON Erp.JobHead.JobNum = Erp.JobAsmbl.JobNum INNER JOIN
Erp.ProjPhase ON Erp.JobHead.JobNum = Erp.ProjPhase.WBSJobNum INNER JOIN
Erp.ProjPhase_UD ON Erp.ProjPhase.SysRowID = Erp.ProjPhase_UD.ForeignSysRowID ON Ice.ChgLog.Key2 = CAST(Erp.JobAsmbl.JobNum AS nvarchar(20)) + '~' + CAST(Erp.JobAsmbl.AssemblySeq AS nvarchar(20)) LEFT OUTER JOIN
Erp.JobMtl_UD INNER JOIN
Erp.JobMtl ON Erp.JobMtl_UD.ForeignSysRowID = Erp.JobMtl.SysRowID ON Erp.JobAsmbl.JobNum = Erp.JobMtl.JobNum AND Erp.JobAsmbl.AssemblySeq = Erp.JobMtl.AssemblySeq
GROUP BY Erp.ProjPhase.ProjectID, Erp.JobAsmbl.JobNum, Erp.ProjPhase.Description, Erp.JobAsmbl.AssemblySeq, Erp.JobAsmbl.DrawNum, Erp.JobAsmbl.RevisionNum, Erp.JobAsmbl.RequiredQty, Erp.JobAsmbl.CommentText, Erp.JobAsmbl.Description, Ice.ChgLog.DateStampedOn, Ice.ChgLog.LogText, Erp.ProjPhase_UD.MachineID_c, Erp.ProjPhase_UD.Machine_c
HAVING (Erp.JobAsmbl.AssemblySeq > 0)
Vielen Dank für eure Hilfe im Voraus
Brian
In der Change Log Tabelle sind mehrere Zeilen (LogText) pro Zeichnungsnummer (DrawNum). Wenn ich die Query so ausführe kriege ich leider mehrere Zeilen pro Zeichnunsnummer ausgegeben, pro ChangeLog Eintrag eine Zeile. Ist es möglich die ChangeLog Einträge irgendwie zusammenzufassen, dass ich pro Zeichnung nur noch eine Zeile habe und die verschiedenen ChangeLog Einträge in einer Zelle zusammengefasst sind? Hier die Syntax meiner View:
SELECT Erp.ProjPhase.ProjectID, Erp.ProjPhase_UD.MachineID_c AS EquipmentID, Erp.ProjPhase_UD.Machine_c AS Equipment, Erp.JobAsmbl.JobNum AS JobID, Erp.ProjPhase.Description AS JobDescription, Erp.JobAsmbl.AssemblySeq AS AssemblyID, Erp.JobAsmbl.Description AS [Assembly Description], Erp.JobAsmbl.DrawNum AS Drawing, Erp.JobAsmbl.RevisionNum AS [Drawing Rev], Erp.JobAsmbl.RequiredQty AS Quantity, Erp.JobAsmbl.CommentText AS Comment, (CASE WHEN SUM(CASE WHEN JobMtl_UD.IsShippingItem_c = 'TRUE' THEN JobMtl_UD.TotalWeight_c ELSE 0 END) = 0 THEN SUM(CASE WHEN JobMtl_UD.IsPreAssembly_c = 'TRUE' THEN JobMtl_UD.TotalWeight_c ELSE 0 END) ELSE SUM(CASE WHEN JobMtl_UD.IsShippingItem_c = 'TRUE' THEN JobMtl_UD.TotalWeight_c ELSE 0 END) END) AS [Weight/Asm], (CASE WHEN SUM(CASE WHEN JobMtl_UD.IsShippingItem_c = 1 THEN JobMtl_UD.TotalWeight_c ELSE 0 END) * JobAsmbl.RequiredQty = 0 THEN SUM(CASE WHEN JobMtl_UD.IsPreAssembly_c = 1 THEN JobMtl_UD.TotalWeight_c ELSE 0 END) * JobAsmbl.RequiredQty ELSE SUM(CASE WHEN JobMtl_UD.IsShippingItem_c = 1 THEN JobMtl_UD.TotalWeight_c ELSE 0 END) * JobAsmbl.RequiredQty END) AS [Total Weight], (CASE WHEN SUM(CASE WHEN JobMtl_UD.IsShippingItem_c = 1 AND JobMtl_UD.FabricationPart_c = 1 THEN JobMtl_UD.TotalWeight_c ELSE 0 END) = 0 THEN SUM(CASE WHEN JobMtl_UD.IsPreAssembly_c = 1 AND JobMtl_UD.FabricationPart_c = 1 THEN JobMtl_UD.TotalWeight_c ELSE 0 END) ELSE SUM(CASE WHEN JobMtl_UD.IsShippingItem_c = 1 AND JobMtl_UD.FabricationPart_c = 1 THEN JobMtl_UD.TotalWeight_c ELSE 0 END) END) * Erp.JobAsmbl.RequiredQty AS [Total FabWeight], CAST(Ice.ChgLog.DateStampedOn AS datetime) AS [Last Rev Date], Ice.ChgLog.LogText AS [Rev Comment]
FROM Ice.ChgLog RIGHT OUTER JOIN
Erp.JobHead INNER JOIN
Erp.JobAsmbl_UD INNER JOIN
Erp.JobAsmbl ON Erp.JobAsmbl_UD.ForeignSysRowID = Erp.JobAsmbl.SysRowID ON Erp.JobHead.JobNum = Erp.JobAsmbl.JobNum INNER JOIN
Erp.ProjPhase ON Erp.JobHead.JobNum = Erp.ProjPhase.WBSJobNum INNER JOIN
Erp.ProjPhase_UD ON Erp.ProjPhase.SysRowID = Erp.ProjPhase_UD.ForeignSysRowID ON Ice.ChgLog.Key2 = CAST(Erp.JobAsmbl.JobNum AS nvarchar(20)) + '~' + CAST(Erp.JobAsmbl.AssemblySeq AS nvarchar(20)) LEFT OUTER JOIN
Erp.JobMtl_UD INNER JOIN
Erp.JobMtl ON Erp.JobMtl_UD.ForeignSysRowID = Erp.JobMtl.SysRowID ON Erp.JobAsmbl.JobNum = Erp.JobMtl.JobNum AND Erp.JobAsmbl.AssemblySeq = Erp.JobMtl.AssemblySeq
GROUP BY Erp.ProjPhase.ProjectID, Erp.JobAsmbl.JobNum, Erp.ProjPhase.Description, Erp.JobAsmbl.AssemblySeq, Erp.JobAsmbl.DrawNum, Erp.JobAsmbl.RevisionNum, Erp.JobAsmbl.RequiredQty, Erp.JobAsmbl.CommentText, Erp.JobAsmbl.Description, Ice.ChgLog.DateStampedOn, Ice.ChgLog.LogText, Erp.ProjPhase_UD.MachineID_c, Erp.ProjPhase_UD.Machine_c
HAVING (Erp.JobAsmbl.AssemblySeq > 0)
Vielen Dank für eure Hilfe im Voraus
Brian