Akhter HUssain

Akhter HUssain

  • 721
  • 1.3k
  • 101.5k

Pivot table query is executing but no data return ,

May 17 2019 8:37 PM
here is my pivot table query ,it is executing but no data return.
 
DECLARE @cols AS NVARCHAR(MAX)
DECLARE @query AS NVARCHAR(MAX)
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT DISTINCT EntryDate INTO #Dates265
FROM Probale
--WHERE (EntryDate BETWEEN @StartDate AND @Enddate)
ORDER BY EntryDate
SELECT @cols = @cols + ',' + QUOTENAME( CONVERT(varchar(20),EntryDate) )
FROM (SELECT DISTINCT DATEPART(DAY, EntryDate) AS EntryDate FROM #Dates265 ) T
ORDER BY EntryDate
--SET @cols = STUFF(@cols, 1, 1, '')
DECLARE @qry NVARCHAR(4000) =
N'SELECT *
FROM (SELECT ItemMasterFile.Descriptionitem,Probale.prdqty,
DATEPART(DAY, Probale.EntryDate)as DDate
FROM Probale Inner Join ItemMasterFile on Probale.Codeitem=ItemMasterFile.Codeitem )prd
PIVOT (Sum(prdqty) FOR DDate IN (' + @cols + ')) AS stat'
EXEC(@qry);
 

Answers (2)