Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Passing integer values separated by coma to a stored procedure
Old 02-21-2007, 04:47 AM Passing integer values separated by coma to a stored procedure
Average Talker

Posts: 16
Trades: 0
Hi all,
Please someone tell me how can I pass integer values separated by coma to a stored procedure to be used in and IN clause.
regards
__________________
Joseph James

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Joseph James is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-21-2007, 03:22 PM Re: Passing integer values separated by coma to a stored procedure
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Simple. Use a string to hold the list of numbers ( string s = "15, 27, 3"; ) and then in the database you'll need to dynamically create a query and use EXECute to run it.
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 02-23-2007, 06:50 PM Re: Passing integer values separated by coma to a stored procedure
Average Talker

Posts: 16
Trades: 0
Thanks for your replay,
That’s simple of course. But this will make the sql to be recompiled every time we execute it. So we may loose one of the main advantage of using a stored procedure.
Regards
__________________
Joseph James

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Joseph James is offline
Reply With Quote
View Public Profile
 
Old 02-23-2007, 09:48 PM Re: Passing integer values separated by coma to a stored procedure
Experienced Talker

Posts: 35
Trades: 0
The only way I can think of is using strings....
eXistenZ is offline
Reply With Quote
View Public Profile
 
Old 02-24-2007, 03:41 AM Re: Passing integer values separated by coma to a stored procedure
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
Quote:
Originally Posted by Joseph James View Post
Thanks for your replay,
That’s simple of course. But this will make the sql to be recompiled every time we execute it. So we may loose one of the main advantage of using a stored procedure.
Regards
That's one advantage of using procs, but there are others, like sending less data back and forth, security, all that great stuff. Your other choices are to just generate a dynamic query on the web server and send it to the database server, you could make a lot of optional parameters to your proc and then use a lot of "or x is null" statements in your where clause.

If you're using SQL Server 2005 you can write your stored procedures in VB or C#, but I wouldn't recommend it. I think SQL 2000 will cache ad hoc queries you throw at it, so "select * from table where id=4" becomes "select * from table where id=?" which is a lot like a stored procedure, except those are compiled when you store them in the DB.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 02-24-2007, 07:28 AM Re: Passing integer values separated by coma to a stored procedure
Average Talker

Posts: 16
Trades: 0
Thanks for your replays
I found an article how to do it in 6 different ways. I thought I should share it with you all.
http://vyaskn.tripod.com/passing_arr...procedures.htm
__________________
Joseph James

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Joseph James is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Passing integer values separated by coma to a stored procedure
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.93969 seconds with 12 queries