Hi All,I am desperately trying to get this dynamic pivot SP to work with the parameters passed to the OPENROWSET, so I can use the results of the SP to insert into a new table. It's the same dynamic pivot from madhivanan's website.I think I have incorrect syntax with the quotation marks in the OPENROWSET, can anyone advise? For the first two parameters I included the comma at the end of the text to create the correct string for the SP.DECLARE @query varchar(1000);DECLARE @column varchar(100);DECLARE @aggregate varchar(100);SET @query = 'SELECT P_ID, I_UID, REF, CRMID, U_UID, SOURCEDB, NDESC, NORDERF, ISPARTNERFLAG, COMPDATE FROM FactProcessStaging WHERE DedupedTask = 1,';SET @column = 'NDESC,';SET @aggregate = 'Count(NDESC)';EXEC( 'SELECT *FROMOPENROWSET(''SQLOLEDB'',''Data Source=DFDSQL2;Trusted_Connection=yes;Integrated Security=SSPI;'',''EXEC BusinessAnalysisDWDev.dbo.dynamic_pivot ''' + @query + '' + '' + @column + '' +'' + @aggregate + ''')')quote:
Originally posted by Michael Valentine Jones
It takes real skill to produce something good out of a giant mess. 