DECLARE @DynamicPivotQuery AS NVARCHAR(MAX) DECLARE @ColumnName AS NVARCHAR(MAX) --Get distinct values of the PIVOT Column SELECT @ColumnName= ISNULL(@ColumnName + ',','') + QUOTENAME(cnt) FROM (SELECT DISTINCT cnt FROM #tmpMfgKbn ) AS Kaban --Prepare the PIVOT query using the dynamic SET @DynamicPivotQuery = N'SELECT DISTINCT order_desc, ' + @ColumnName + ' FROM #tmpMfgKbn PIVOT(MAX([status]) FOR cnt IN (' + @ColumnName + ') ) AS PVTTable' --Execute the Dynamic Pivot Query EXEC sp_executesql @DynamicPivotQuery
Gain unlimited access to on-demand training courses with an Experts Exchange subscription.Get Access
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE
Connect with Certified Experts to gain insight and support on specific technology challenges including: