Sunday, February 19, 2012

How to query data by various amount of filter value ??

Generally, on any screen, we design filter screen by allowing user to identify range or one value to search.

But sometime in some screen, It will be more convenient for user if user can identify No matter how value to search.

For example

On screen which have information of people in any province.

So user would like to search it by identify no matter how value to search.

There are check box of any province on filter part which enable users choose it.

Hence, if sometime user choose (by clicking on checkbox) 3 provinces : LA, Michigan, WachingtonDC to see description only 3 chosen province.

and sometime user choose (by clicking on checkbox) 2 provinces : LA, Michigan to see description only 2 chosen provinces.

Please give me any idea for create Stored Procedure or any tecnique to complete my idea...

Help me Pleaseeeee

CryingCryingCrying

If you want to use a stored procedure, the problem is a little more complicated, because you must use dynamic SQL. If you are using SQL 2005, see sp_executesql. If you just want to build an SQL string in your ASP page, you can set the checkboxes to postback, and handle the CheckChanged event. Build up a Comma seperated list of the values that are checked, and add a where clause to the SQL statement that looks like "WHERE province IN (" + ListOfProvinces + ")". Of course, if there is nothing checked, perhaps you want to show all the records, so you should drop the where clause, or maybe you don't want to show any, so you could just set the ListOfProvinces to an empty string.

No comments:

Post a Comment