I built a dynamic SQL statement in a string named strSQLFS and passed it along as a parameterized stored procedure as follows:
I wanted to perform a Transferspreadsheet to output the result of this stored procedure to an Excel file. However I believe you cannot pass a dynamic SQL statement to the Transferspreadsheet function. Is there a way I could pass the result of this stored procedure to the Transferspreasheet function if I want to export the result to an Excel spreadsheet.
Is there a way to convert the result of the dynamic query to a table since Transferspreadsheet can output a table to an Excel file.
Or else could I somehow convert the result of the strored procedure, a recordset to a table and then use the Transferspreadsheet with the newly created table ?
-----------------------------------------------------------
With com
Set .ActiveConnection = cn
.CommandType = adCmdStoredProc
.CommandText = "dbo.procUDFl"
.Parameters.Append .CreateParameter("@prmSQL", adVarChar, adParamInput, 8000, strSQLFS)
.Parameters.Append .CreateParameter("@RptYearF", adInteger, adParamInput, 4, intYearSP)
Set rstQueryFS = .Execute
End With
-----------------------------------------------------------
CREATE PROCEDURE dbo.procUDFl
@prmSQL varchar (8000),
@RptYearF int
AS
SET @prmSQL = REPLACE(@prmSQL,'intYearSP',CAST(@RptYearF AS CHAR(4)))
EXEC( @prmSQL)
GO
I wanted to perform a Transferspreadsheet to output the result of this stored procedure to an Excel file. However I believe you cannot pass a dynamic SQL statement to the Transferspreadsheet function. Is there a way I could pass the result of this stored procedure to the Transferspreasheet function if I want to export the result to an Excel spreadsheet.
Is there a way to convert the result of the dynamic query to a table since Transferspreadsheet can output a table to an Excel file.
Or else could I somehow convert the result of the strored procedure, a recordset to a table and then use the Transferspreadsheet with the newly created table ?
-----------------------------------------------------------
With com
Set .ActiveConnection = cn
.CommandType = adCmdStoredProc
.CommandText = "dbo.procUDFl"
.Parameters.Append .CreateParameter("@prmSQL", adVarChar, adParamInput, 8000, strSQLFS)
.Parameters.Append .CreateParameter("@RptYearF", adInteger, adParamInput, 4, intYearSP)
Set rstQueryFS = .Execute
End With
-----------------------------------------------------------
CREATE PROCEDURE dbo.procUDFl
@prmSQL varchar (8000),
@RptYearF int
AS
SET @prmSQL = REPLACE(@prmSQL,'intYearSP',CAST(@RptYearF AS CHAR(4)))
EXEC( @prmSQL)
GO