Solved

Stored Procedure

Posted on 1998-12-07
9
175 Views
Last Modified: 2010-03-19
Hi
I am trying to pass parameters to a stored procedure , this paremeter will be used in an "in" clause. Since i cannot pass an array as parameter i am trying to concatenate the different values in the or class into a string and send as a varchar and execute the SQL in the procedure using EXEC statement. But sometimes this concatenated "in" clause parameters exceeds 255 characters. so i cannot pass it as a varchar. what would be the solution
0
Comment
Question by:varsha2
  • 5
  • 2
  • 2
9 Comments
 
LVL 2

Expert Comment

by:tschill120198
ID: 1092097
You could pass the values in using a varchar field, parse each value into a table, and join to that table in your query instead of using "in"... performance won't be optimal due to the parsing, though.
0
 

Author Comment

by:varsha2
ID: 1092098
I cannot pass the parameter using a varchar field because all the parameters together exceeds 255 characters
0
 
LVL 2

Expert Comment

by:tschill120198
ID: 1092099
How about using multiple varchar parameters?
0
 

Author Comment

by:varsha2
ID: 1092100
I craete the in clause dynamically and i may not be able to determine how many varchar i might need to send as input parameter. this basically prevents me from determining how many input parameters the stored procedure can have
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 2

Accepted Solution

by:
tschill120198 earned 50 total points
ID: 1092101
Surely there must be a limit at some point... say, 10 varchar parameters?  20? 30?  They don't all have to be used, so if a particular query doesn't need all of them, they can default to null; the sproc doesn't parse them if they are null.  This is probably your best solution.
An alternative solution would be to have a seperate sproc that is called repeatedly (once for each value you want to query against) and this sproc inserts the values into a table.  When all values have been entered, you call the sproc that performs the main query.


0
 
LVL 1

Expert Comment

by:ivanh
ID: 1092102
The quick answer would be as a text datatype, but I'm not sure
what that does for performance.  I use it on one of my queries
for the same type of reason and I don't notice any performance problems.
0
 
LVL 2

Expert Comment

by:tschill120198
ID: 1092103
Agreed... a text parameter would be a cleaner solution to the parameter issue.  But how would you parse the text field for the different values you are searching on?
0
 
LVL 1

Expert Comment

by:ivanh
ID: 1092104
He said that he was going to concatenate the string into the
format for execution in the IN statement and then run the EXEC statement to run the query.

EXEC ("select * from mytable where name in (" + in_str + ")")

in_str would be something like "'a','b','c','d'".
0
 
LVL 2

Expert Comment

by:tschill120198
ID: 1092105
ivanh is correct... his answer should work.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now