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 2000 Forums
 SQL Server Development (2000)
 Stored Procedure and Dynamic SQL

Author  Topic 

imp_galo
Starting Member

13 Posts

Posted - 2005-12-20 : 06:57:46
I've a C++ app in which the user can define custom filters. So there are a lot of fields he can select to filter or not.
I've been using dynamic SQL and I just append the column name and the column value to the where clause. Is there any way I can use SP in this case? Is it preferable?

thx in advance.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-20 : 07:01:15
In this topic look for Where in @mysql
http://sqlteam.com/forums/topic.asp?TOPIC_ID=55210

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

imp_galo
Starting Member

13 Posts

Posted - 2005-12-20 : 17:53:51
Sorry madhivanan but I didn't quite get it. My problem is the following: I have a table named MyTable and the columns Cl1, Cl2, Cl3.
According to the custom filters the user can choose, for example:
1- select Data from MyTable where Cl1 = Value; or
2- select Data from MyTable where Cl2 = Value; or
3- select Data from MyTable where Cl3 = Value.

Is there anyway I can fit it in a SP?

thx again.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-12-20 : 18:23:53
The trick to a dynamic WHERE clause without using dynamic SQL is to use COALESCE. Here is the SQLTeam article that explains this approach:
http://www.sqlteam.com/item.asp?ItemID=2077

Tara Kizer
aka tduggan
Go to Top of Page
   

- Advertisement -