Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 3708 on Stored Procedure with a parameter 1

Status
Not open for further replies.

git2dn

Programmer
Joined
Apr 7, 2005
Messages
12
Location
US
I created a dynamic query in my Access application as a SQL string. The user selects values from various controls on the screen including list boxes and based on the values selected from the varous controls, I built a SQL string.

Now I want to pass along the SQL string named strSQL to a Stored Procedure using a parameter.

I coded the following in my Access application to execute a stored procedure named dbo.procUDFl with a parm named prmSQL, which contains a complete SQL statement.

Let's assume the value for parameter prmSQL is as follows:

SELECT * FROM tblStates WHERE STATE = 'NY';

I tried to execute the Stored Procedure dbo.procUDLl with parameter prmSQL.

However, I get an error 3708 on the Append statement which follows:

----------------------------------
I coded the following:

Option Explicit
Dim prmSQL As ADODB.Parameter
...

strSQLFS = "Select * from dbo.tblCustomers;"

Set com = New ADODB.Command
With com
.CommandType = adCmdStoredProc
.CommandText = "dbo.procUDFl"
.Parameters.Refresh
.Parameters.Append .CreateParameter("@prmSQL", adVarChar, adParamInput, , strSQLFS)
.ActiveConnection = cn
Set rstQueryFS = .Execute
End With
-----------------------------------------------------------
I coded the stored procedure as follows:

CREATE PROCEDURE dbo.procUDFl

@prmSQL varchar (4000)

AS

EXEC(@prmSQL)
GO

 
The adVarChar needs a length for one thing.

Parameters.Append .CreateParameter("@prmSQL", adVarChar, adParamInput,4000 , strSQLFS)
 
cmmrfrds, your observation was exactly what I needed

thanks a million.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top