no that wont work as I would have to write protentually hundreds of differen
t
queries to handle different conbinations of the query
"Uri Dimant" wrote:
> Based on your narrative I can suggest something like that
> create proc myproc
> @.x int,
> @.y int,
> @.op int -- 1 for AND, 2 for OR
> as
> if op=1
> begin
> select * from table
> where x=coalesce(@.x,x) and y=coalesce(@.y,y)
> end
> if op=2
> begin
> select * from table
> where x=coalesce(@.x,x) or y=coalesce(@.y,y)
> end
>
> "Marcel" <Marcel@.discussions.microsoft.com> wrote in message
> news:61386D81-280C-425D-9C99-3E9170ECF8F0@.microsoft.com...
>
>Marcel
http://www.sommarskog.se/dyn-search.html
"Marcel" <Marcel@.discussions.microsoft.com> wrote in message
news:5812BA18-16D8-4DA2-9621-7B1E1001FDDE@.microsoft.com...
> no that wont work as I would have to write protentually hundreds of
> different
> queries to handle different conbinations of the query
> "Uri Dimant" wrote:
>|||Marcel (Marcel@.discussions.microsoft.com) writes:
> no that wont work as I would have to write protentually hundreds of
> different queries to handle different conbinations of the query
If the purpose is to provide a generic search routine, then read the
article that Uri posted a link to. Being the author, I like to think
that's a good article.
If the purpose is something else, consider writing several stored
procedures. The norm for stored procedures is that they are static,
and address a certain problem.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx
Friday, March 9, 2012
dynamically changing or concatenating the where statment in a
Labels:
changing,
conbinations,
concatenating,
database,
differentqueries,
dimant,
dynamically,
handle,
hundreds,
microsoft,
mysql,
oracle,
protentually,
query,
server,
sql,
statment,
uri,
write
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment