Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 OPENROWSET with multiple Stored Proc Parameters

Author  Topic 

Humate
Posting Yak Master

101 Posts

Posted - 2010-06-02 : 11:34:58
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 *
FROM
OPENROWSET
(
''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.

Humate
Posting Yak Master

101 Posts

Posted - 2010-06-03 : 05:09:34
This is the error message I receive for the above query:

Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'SELECT'.
Msg 102, Level 15, State 1, Line 6
Incorrect syntax near ','.
Msg 105, Level 15, State 1, Line 6
Unclosed quotation mark after the character string ')'.

I just can't see the problem syntax here.

Go to Top of Page
   

- Advertisement -