Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Where do you think my SQL code should sit?

Author  Topic 

token
Posting Yak Master

133 Posts

Posted - 2012-10-23 : 07:51:41
Question: Where to put a SQL query that powers a webpage which lets users to select multiple values to filter on?

Normally I would write the SQL inline within the webpage and allow the application code (PHP, ASP, Coldfusion etc) to get the values selected by the user from a listbox and loop through adding an 'AND' or 'OR' clause after each line.

Is there any way to do this within SQL as a Stored Procedure? So far I can't think of any way to do it. For a column called ProductName, you could literally have hundreds of different values to put in the WHERE clause. Any ideas?

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-10-23 : 11:13:06
yeah -- pass the list of values as a table valued parameter to the stored proc

then inside the sp join to that table valued parameter.

You'd get good cache reuse from the front end db cache on the list.

More info:
http://www.sommarskog.se/arrays-in-sql-2008.html

Transact Charlie
Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/
Go to Top of Page
   

- Advertisement -