Link to home
Start Free TrialLog in
Avatar of hidrau
hidrauFlag for Brazil

asked on

Passing values to run a store procedure

Hello guys,

I have a store procedure that will be run retrieving me a query. But before it retrieves me a query, some operation it will run and after the query is created. This query must be passed by parameter to be assemble.

I am getting error to pass this query,

This is the query:

'SELECT * FROM (
SELECT Contas, Descricao, Totaliza,
TOTAL =
IsNull(A.sete,0) ,
IsNull(A.sete,0) as ''setembro''
FROM ( Select *,
''sete''= Isnull((select Sum(ContSalContValor) from contsaldoanalitico WHERE
SubString(ContSalContCodigo,1,Len(Contas)) = Contas and
SubString(Convert(char(10),ContSalContData,112),1,6) = ''200609''),0)
From #TbRel) A
) B
WHERE B.TOTAL<>0
ORDER BY B.CONTAS'


 Here I try to pass the query
  ADOStoredProc1.Parameters.ParamByName('@Sql').Value := Str;
  ADOStoredProc1.Open;
Avatar of cobi100
cobi100

what is the error?
ASKER CERTIFIED SOLUTION
Avatar of BlackTigerX
BlackTigerX

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hidrau

ASKER

It don't run.

Sorry, but I had to give up this thread.

I need to close it

Avatar of hidrau

ASKER

BlackTigerX , it is a storeprocedure, I should pass by parameter this query.

but I had to give up :(
you are passing the text of a query as a parameter to a stored procedure?

not a good idea, you might as well just execute the query directly on your code
Avatar of Wim ten Brink
I agree with BlackTigerX here. Passing SQL code to a stored procedure is one of the worst developing errors that you can make in my opinion. Whomever came up with that idea should be [edit], [edit] and finally [edit] and never be allowed near any computer again...
Avatar of hidrau

ASKER

Ok Workshop_Alex , I changed my mind about it.

Thanks
You're welcome. Glad I could help. :-) But BlackTigetX deserves the credits...