I work on SQL server 2012 I face Issue I implement dynamic SQL it very slow
so I need to enhance statement below to work quickly
- DECLARE @SQL NVARCHAR(MAX)
- select @SQL =CONCAT('
- SELECT * Into #NewTable
- FROM #SplitNumberAndUnitsFinal
- PIVOT(max(Value) FOR DKFeatureName IN ('+@Columns+')) AS PVTTable
- ',
- N' Select ''Variant ID'' as ''[Variant ID]'',''PART_ID'' as ''PART_ID'' ,''Vendor ID'' as ''Vendor ID'',''Manufacturer'' as ''Manufacturer'',''Digi-Key Part No.'' as ''Digi-Key Part No.'' ,''Mfr Part No.'' as ''Mfr Part No.'' ,''Description'' as ''Description'',''Category'' as ''Category'',''Family'' as ''Family'',''Obsolete'' as ''Obsolete'' ,''Non-Stock'' as ''Non-Stock'' , ''Part Status'' as ''Part Status'',''PartNumber'' as ''Z2 Part number'' , ''CompanyName'' as ''Z2 Manufacturer'' , ' +@Header + '
- union all
- select [Variant Number],PART_ID,[Vendor ID],Manufacturer,[Digi-Key Part No.] ,[Mfr Part No.],[Description],Category,Family ,Obsolete ,[Non-Stock] , [Part_Status], PartNumber , CompanyName , ' +@Columns + ' from #NewTable
so please any advice for code above to enhance it to work quickly ?
so are there are any thing wrong you see on code above ?