SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Execute SQL task/Stored procedure with parameters issue


Execute SQL task/Stored procedure with parameters issue

Author
Message
stricknyn
stricknyn
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1484 Visits: 690
Hello, it seems like I'm doing this right and most of the examples on the net I've found have it this way too, so I'm not sure what I'm donig wrong.

Ok, I have a execute SQL task in my SSIS package which should fire a stored procedure which has 2 parameters (@StartDate and @EndDate). The stored procedure runs fine using a exec statement: exec [dbo].[zKMHP_Proprietary] '10/1/2007', '10/31/2007'

If I take the above statement and put it in a Execute SQL task and hit parse, it parses successfully. Now if I replace my values with parameters this statement (exec [dbo].[zKMHP_Proprietary] ?, ?) I get the error: "The query failed to parse. Syntax error, permission violation, or other nonspecific error"

I do have my parameter mapping with these two as well in the execute sQL task, but at the very least it should parse correctly since according to everywhere I've looked on the net this is the way to feed parameters into a stored procedure from SSIS execute SQL task. What am I doing wrong?

Thanks,

Strick



Michael Earl-395764
Michael Earl-395764
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13451 Visits: 23078
The parse button does not work with question mark (?) parameterized queries. Does the task execute successfully?
stricknyn
stricknyn
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1484 Visits: 690
Yep you were right the task executes successfully. Thanks. But now I have a new issue stemming from this

The execute SQL task which runs the statement exec [dbo].[zKMHP_Proprietary] ?, ?) will run just fine, but the results of this stored procedure need to be inserted into another table. When I modify it to be:

INSERT INTO insert into zKMHP_Staging
exec [dbo].[zKMHP_Proprietary] ?, ?)

the task fails. I know the above statement is correct because if I take it and copy it to SQL Mgmt Studio, then change it to

INSERT INTO insert into zKMHP_Staging
exec [dbo].[zKMHP_Proprietary] '10/1/2007', '12/31/2007')

it runs just fine. Ideally, I'd rather use a data flow task to insert the results of a stored procedure into a table, but just haven't figured out how to do this since there are no outputs at design time. So I've tried using the Execute SQL task instead. But anyway, I'm not sure why it won't run when all I do is add the insert into to the task. Can you see anything else wrong?

Thanks,

Strick



Michael Earl-395764
Michael Earl-395764
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13451 Visits: 23078
Step 1 of dealing with digging yourself into a hole is to stop digging.
Here is what I think your situation is.

You have a procedure with some relatively complicated logic in it. The procedure uses a temp table and returns data from the temp table as the output data set.

The first thing to ask is if the business logic needs to be in a procedure. Can you do the logic in SSIS as efficiently or better? If so, write the logic pf the procedure in SSIS.
If you need to use a procedure for some reason, having a temp table can be a problem for SSIS because it cannot get column information at design time. To get around this, you can use a global temp table while designing and keep the table in a session that you do not close. You can even just create a stub version of your procedure that does nothing but select the column set:

CREATE PROC MyProc
AS
SELECT 'A' AS Col1, 'B' AS Col2...

This will allow you to have SSIS build the input and output columns (be very careful of data types).

You can do what you are suggesting - just run an insert from a procedure, but I would avoid it especially in the way you are doing it. If you must do this, include the insert as part of the procedure (even if you need to wrap this procedure with another one).
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search