Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Use parameters with Execute SQL task


Use parameters with Execute SQL task

Author
Message
Kathi Kellenberger
Kathi Kellenberger
Right there with Babe
Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)

Group: General Forum Members
Points: 787 Visits: 341

I would like to use a parameter with the execute sql task but nothing is working like BOL says it should. I am using the June CTP.

I have a query something like

Select ProductID, ProductName
from Production.Product
Where ProductID = ?

The Parameter mapping page looks like this:
User:roductID, Input, Long, ?

Clicking Parse Query returns this: "The query failed to parse. Parameter Information cannot be derived from SQL statements. Set parameter information before preparing command."

BOL also says you can do this

Select ProductID, ProductName
from Production.Product
where ProductID = @Param1

Parameter Mapping page:
User:roductID, Input, Long, @Param1
OR
User:roductID, Input, Long, ?

Returns error "The query failed to parse. Must declare the scalar variable @Parm1.".

The only way to clear this error is by declaring @Param1 inside the SQL statement.

Declare @Param1 int
Select ProductID, ProductName
from Production.Product
where ProductID = @Param1

But this doesn't actually send User:roductID in place of @Param1.

I have also tried this

Select ProductID, ProductName
from Production.Product
where ProductID = Param1

with Parameter Mapping page:
User:roductID, Input, Long, Param1

The query will parse, but errors out when executed. By running Profiler, I can see that the statement is passed to SQL as is, without the replacement.

Any help will be appreciated. I have a big deadline in a couple of days.

Kathi



Aunt Kathi
Linchpin People Teammate
SQL Server MVP
Author of Expert T-SQL Window Functions
Site Owners
Site Owners
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10093 Visits: 1
No one has responded to this topic yet. Even if you don't have a complete answer, the original poster will appreciate any thoughts you have!
Rootman
Rootman
SSC-Addicted
SSC-Addicted (489 reputation)SSC-Addicted (489 reputation)SSC-Addicted (489 reputation)SSC-Addicted (489 reputation)SSC-Addicted (489 reputation)SSC-Addicted (489 reputation)SSC-Addicted (489 reputation)SSC-Addicted (489 reputation)

Group: General Forum Members
Points: 489 Visits: 489

Hello Kath

I experienced similar problems when trying to do this. In the end I resorted to a stored proc, and passing the parameters seemed to work just fine.





JB-242273
JB-242273
SSC Rookie
SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)

Group: General Forum Members
Points: 33 Visits: 6

what data type of your variable???

i experiance the same problem in the past i set to my variable type Int, however i changed the type to integer or decimal and it's work.

------------------------------------------------------------

Imagination is more important then knowledge



. . .
Kathi Kellenberger
Kathi Kellenberger
Right there with Babe
Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)

Group: General Forum Members
Points: 787 Visits: 341
I finally got a good answer on this one. Use '?' as the placeholder in the query and use numbers starting at 0 for the parameter name. Works like a charm!

Aunt Kathi
Linchpin People Teammate
SQL Server MVP
Author of Expert T-SQL Window Functions
Jamie Thomson
Jamie Thomson
SSC Eights!
SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)

Group: General Forum Members
Points: 885 Visits: 188

Kathi,

I think BOL is a bit light on this. Could you use the "Send Feedback" link on the appropriate page to let the author know - it seems alot of people have had this problem!

-Jamie



Jamie Thomson
http://sqlblog.com/blogs/jamie_thomson
Kathi Kellenberger
Kathi Kellenberger
Right there with Babe
Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)

Group: General Forum Members
Points: 787 Visits: 341
I talked with a developer at MS about this. He said that the parameters for each provider is different and right now, there is no source listing the differences. There should be a white paper by RTM.

Aunt Kathi
Linchpin People Teammate
SQL Server MVP
Author of Expert T-SQL Window Functions
David Vann
David Vann
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 24
I don't understand how this worked. Can you send a sample?
Kathi Kellenberger
Kathi Kellenberger
Right there with Babe
Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)

Group: General Forum Members
Points: 787 Visits: 341
This parameter stuff just about drove me nuts. All my 2005 stuff is at home, so I'll try to post how I solved the problem tonight.

Aunt Kathi
Linchpin People Teammate
SQL Server MVP
Author of Expert T-SQL Window Functions
Kathi Kellenberger
Kathi Kellenberger
Right there with Babe
Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)

Group: General Forum Members
Points: 787 Visits: 341

Depending on the type of connection, the parameters are set up differently. Even then, things didn't always work for me. If you use an ADO.NET connection manager, the parameters should start with the @ symbol. If you use the OLE DB connection manager, the parameters are numeric starting with 0. I had the best luck with the ADO.NET connection manager.

I am trying to find out from MS if there is a white paper available. I'll post what I find out here.



Aunt Kathi
Linchpin People Teammate
SQL Server MVP
Author of Expert T-SQL Window Functions
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