Thursday, March 29, 2012

How Query Question

I have a form where users pick multiple values. I then want to run a query against the Sql Server backend and limit the result set based on the multiple picks the user just made.

IF those picks were in a 2nd table - it would look like:

Select * from firsttable join secondtable on firsttable_pk=secondtable_fk

The problem is that this hypothetical 2nd table would be local to the application, not on the back end.

I could store those pick in an Array, but not sure if that can be passed to the back end for use in a query.

Any suggestions?

Thanks,I've solved this problem in the past by inserting the selected values into a SQL Server #Temp table, and then joining to that table in my select statement. This works as long as each user has their own connection.|||Thanks blindman. I'll check BOL for the #TEMP table and give it a try. Each user will have their own connection.|||I've also used a User Defined Function for a similar purpose. I pass in a list of values separated by commas and then a UDF to parse them into a table. Then you can join to that.

Here is a link to one possible version of the ParseString Function: http://www.codeproject.com/database/SQL_UDF_to_Parse_a_String.asp

No comments:

Post a Comment