SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Multiple condition based on where clause in sql server 2008


Multiple condition based on where clause in sql server 2008

Author
Message
SQL006
SQL006
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1103 Visits: 1330
I had a table Product with these fields

ProductName,
Description,
Manufacturer,
Product Code,
Technology,
Address,
Country,
City,
Length


I want to search all these fields with these criteria

SearchType='Contains'
SearchType='Ends'
SearchType='Equals'
SearchType='Greater'
SearchType='Less'
SearchType='Not Equal'
SearchType='Like'


Another parameter i will pass whether to use AND/OR operation

At a time we can search 6 fields with any of the search criteria and AND\OR operation

the condition in where clause will be like this

WHERE (ProductName = @ProductName) AND (Country Like @Country +%) OR (Manufacturer Likre(Ends) '%' + @Manufacturer ) AND (Length < (Greater) @Length)



So the user can input 6 conditions based on the above criteria.

Can u help to get the logic for where clause
GilaMonster
GilaMonster
SSC Guru
SSC Guru (230K reputation)SSC Guru (230K reputation)SSC Guru (230K reputation)SSC Guru (230K reputation)SSC Guru (230K reputation)SSC Guru (230K reputation)SSC Guru (230K reputation)SSC Guru (230K reputation)

Group: General Forum Members
Points: 230316 Visits: 46344
http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/

You'll need dynamic SQL on this one.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


SQL006
SQL006
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1103 Visits: 1330
GilaMonster (3/25/2013)
http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/

You'll need dynamic SQL on this one.


Thanks gail for the reply..let me go through the article

I am planning to pass the condition as a table value parameter, each row has a different condition
Chk the attached picture below
I am attaching the search diagram where i have to use this procedure
Attachments
filter.JPG (19 views, 40.00 KB)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search