0
SET @InventoryQuery = N'SELECT * FROM 
             (
                  SELECT Inven.Inventory_ID As ID,Inven.Inventory_ID As Number, Inventory_Date As ActionDate, ''Inventory'' AS [ActionType], IsNull(Sum(Product_Qty),0) Product_Qty,  P.Product_Desc_ENG + '' ('' + P.Product_Weight + '')'' Product_Desc_ENG
                FROM  CRM.Product P 
                INNER JOIN [crm].[InventoryDetail] InvenDet ON P.Product_ID = InvenDet.Product_ID
                INNER JOIN [crm].[Inventory] Inven ON Inven.Inventory_ID = InvenDet.Inventory_ID
                WHERE Inven.Customer_Id = ' + CAST(@CustomerID AS VARCHAR(10)) +
                 ' AND ( Inven.Inventory_Date BETWEEN ' + CONVERT(VARCHAR(20), @StartDate, 121) + '
                   AND ' + CONVERT(VARCHAR(20), @EndDate, 121) + ' ) GROUP BY Inven.Inventory_ID, Inventory_Date,P.Product_Desc_ENG,P.Product_Weight
            ) y
            pivot 
            (
               sum(Product_Qty)
                for Product_Desc_ENG in (' + @cols + N')
            ) p2 '
OldProgrammer
  • 12,050
  • 4
  • 24
  • 45
  • See https://stackoverflow.com/questions/1586560/how-do-i-escape-a-single-quote-in-sql-server – PM 77-1 Jun 13 '21 at 19:34
  • Does this answer your question? [How do I escape a single quote in SQL Server?](https://stackoverflow.com/questions/1586560/how-do-i-escape-a-single-quote-in-sql-server) – Stu Jun 13 '21 at 21:10
  • Edit to add database tag and programming language tag. – June7 Jun 14 '21 at 00:17

0 Answers0