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 2005 Forums
 Transact-SQL (2005)
 Filtering Data

Author  Topic 

lfernandesfotos
Starting Member

2 Posts

Posted - 2010-09-27 : 13:03:03
Hello!!!

I have several procedures that uses in my point of view, WORST PRACTICES when filtering data. For exemple, to filter some status in the SQL we use to Concate Strings with the filteres:

set @filterCustomer = @filterCustomer + ' and testUser = 0'

The problem is that the query is all set in the variable @filterCustomer, generating a long string that will be called by an Exec command.

This one is dificult to maintain, so there is another way on filtering data without using String Concate?

===========
Luiz Fernandes
lfernandesfotos@hotmail.com

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-09-28 : 11:29:29
You can use this logic

where
(col=@col1 or @col1 is null)
and
(col=@col2 or @col2 is null)
and
.
(col=@colN or @colN is null)


Madhivanan

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

- Advertisement -