February 23, 2005 at 3:48 pm
Hi,
I have a list of all the userids which I want to pass as a parameter to a stored procedure from my webpage. Can any one tell me which is the best way to do this? The list size is big, around 25,000 userids.
I am using C#
Thanks.
February 23, 2005 at 4:11 pm
February 23, 2005 at 4:18 pm
25,000 items That's some list.
Even if each of these 25,000 values is only one digit, you'll still exceed the limits of the varchar datatype so you'll need to use text. That comes with its own problems and caveats.
Maybe you should look at an alternative method of getting these values into a database table, like saving them to a text file first or something like that.
--------------------
Colt 45 - the original point and click interface
February 23, 2005 at 4:48 pm
Actually I tried sending the list as a text variable parameter, a comma seperated text and convert each userid back to int. I have a table variable inside the stored proc and I convert each userid to int and store it in the table. It worked couple of times. But now it is throwing an error, Syntax error converting the varchar value '6633,156,150,1559' to a column of data type int.
I checked sql profiler. It looks like it times out inside the loop, where I get userid one by one. After looping through n times, it stops at one point - sql:stmt starting @intid = convert(int, @stringid). Then rpc:starting exec sp_reset_connection. It stops here.
February 24, 2005 at 1:43 am
You might want to read thoroughfully through the article PW referenced. It should give you some ideas.
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
February 24, 2005 at 5:37 am
The article on Dynamic SQL linked by PW is very comprehensive.
How did the 25,000 user IDs get to the webpage in the first place? Did they come from the database? 25,000 is too many for input or selection by a user....
These 25,000 items should be in a table in the DB, maybe with a "SELECTED" boolean field if there are more that aren't used, make your query join onto that.
Or am I way off the mark here? Passing 25,000 of anything to (or from) a web page just does not sound like a good idea
February 24, 2005 at 6:54 am
Yea, I'd agree with all of the above. My thoughts are to create a table / temp table that you can populate with the 25,000 ids, then use a subquery in the SP to reference them. It may be possible to create a table variable type too. You may want to experiment with the different methods to see what's faster.
Cheers.
February 24, 2005 at 10:20 am
The 25000 entries come from a webpage. I have a search clients page, where users can search for and select the clients. And there are mroe than 25000 users in the database, so in the worst case all of them can be selected. I can store it in some table but what if more than one user run the function simultaneously.
February 24, 2005 at 10:24 am
You have a UI that displays all 25,000 clients to the user in some sort of user-selectable grid or list ? How can "all" be selected ?
I think maybe the problem is not getting 25,000 ID's back to the DB, but in the design of a UI that presents 25,000 selectable items to a user ...
February 24, 2005 at 10:29 am
The search results are presented in a grid. User can click on 'select all' or 'select none'. I am not sure there is another way of designing the UI. It is a search page and if the user does not enter any search criteria or enters something that eliminates only few users, I have to display around 25000 results.
February 24, 2005 at 10:36 am
25000 results is practically unusable to any user. Maybe you should place a limit on the rows returned, which, if exceeded gives a warning of "There were more rows returned than you can possibly consider viewing" or similar, so that the result is the user re-running the query with more restrictive search filters.
This in turn will produce a more managable set of ID's going into your stored procedure.
February 24, 2005 at 10:41 am
But this search page is for admin, not for public users. They might want to view all the users or export all the users into a csv list for some admin work. So I cannot put a limit on that.
February 24, 2005 at 12:43 pm
A good design pattern would be to transfer the selected items between the web page and the web server as XML data. Then you can design the stored procedure with a single parameter that takes the XML string. Then you use OPENXML inside the procedure to get to you data and use it in subsequent queries.
HABIB.
February 25, 2005 at 3:02 pm
WRT limiting the select options:
You could always consider "all" as a special option - pass a flag instead of passing the actual user ids. Should be a bit faster, since you don't have to parse out 25,000 id values. Then, if they don't want "all", they're limited to 500 or 1,000 records. large enough that they can grab a bunch at once if they need to, but not so large that things get out of hand.
This may avoid the time-out issue with your old methodology.
Of course, the question "Is it possible to rework the UI at this point" arises....
R David Francis
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply