2016-10-08 14 views
0

Ich habe die folgende Select-Anweisung, die für mich funktioniert.Kombinieren mehrerer WHERE-Klauseln

select * 
from BND_listing right 
join BND_ListingCategories on BND_Listing.CatID = BND_ListingCategories.CatID 
where 
    (CategoryName = '[querystring:filter-Category]' or 
    '[querystring:filter-Category]' = 'All') 
    and (City = '[querystring:filter-City]' or 
     '[querystring:filter-City]' = 'All') 
    and (Region = '[querystring:filter-State]' or 
     '[querystring:filter-State]' = 'All') 
    and (Country = '[querystring:filter-Country]' or 
     '[querystring:filter-Country]' = 'All') 
    and isnull(Company,'') <> '' 
order by 
    Company asc 

Zusätzlich zu dem, was es tut Ich mag würde folgendes umfassen WHERE-Klausel, die im Grunde nur erlaubt mir, eine „Search Box“

DECLARE @param VARCHAR(MAX) 
SET @param = '[querystring:searchterm]' 

SELECT Company 
FROM BND_Listing 
WHERE Company LIKE '%' + @param + '%' 

zu schaffen, ist es möglich, diese beiden zu kombinieren Anweisungen in eins auswählen und alle Funktionen behalten?

Antwort

1
DECLARE @param VARCHAR(MAX) 
SET @param = '[querystring:searchterm]' 


select * 
from BND_listing right 
join BND_ListingCategories on BND_Listing.CatID = BND_ListingCategories.CatID 
where 
    (CategoryName = '[querystring:filter-Category]' or 
    '[querystring:filter-Category]' = 'All') 
    and (City = '[querystring:filter-City]' or 
     '[querystring:filter-City]' = 'All') 
    and (Region = '[querystring:filter-State]' or 
     '[querystring:filter-State]' = 'All') 
    and (Country = '[querystring:filter-Country]' or 
     '[querystring:filter-Country]' = 'All') 
    and isnull(Company,'') <> '' 
    AND Company LIKE '%' + @param + '%' 
order by 
    Company asc 
+0

Danke @tuxmania – UserSN

Verwandte Themen