SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 multiple Column Query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yonkouturko
Yak Posting Veteran

Philippines
59 Posts

Posted - 10/02/2013 :  23:07:40  Show Profile  Reply with Quote
THIS IS MY QUERY
declare @PRODUCT_CATEGORY as VARCHAR(MAX)
declare @ITEMCATEGORY as VARCHAR(MAX)
declare @INTERFACE as VARCHAR(MAX)
declare @CAPACITY as VARCHAR(MAX)
declare @DESCRIPTION as VARCHAR(MAX)
declare @CONDITION as VARCHAR(MAX)
declare @BRAND as VARCHAR(MAX)
set @PRODUCT_CATEGORY =''
set @ITEMCATEGORY =''
set @INTERFACE =''
set @CAPACITY =''
set @DESCRIPTION =''
set @CONDITION =''
set @BRAND =''
SELECT BARCODE, ProductCategory, ItemCategory, Brand, Capacity, Interface, Condition, Others, Model, PRODUCT_DESCRIPTION, Quantity, Barcode_Type
FROM Table_Product_Tagging
WHERE (ProductCategory LIKE '%'+ @PRODUCT_CATEGORY +'%') AND (ItemCategory LIKE '%'+ @ITEMCATEGORY +'%') AND (Interface LIKE '%'+ @INTERFACE +'%') AND (Capacity LIKE '%'+ @CAPACITY +'%') AND (PRODUCT_DESCRIPTION LIKE '%' + @DESCRIPTION + '%') AND (Condition LIKE '%'+ @CONDITION +'%') AND (Brand LIKE '%'+ @BRAND +'%')


I HAVE 600+ RECORDS IN MY TABLE_PRODUCT_TAGGING but in only displayed almost HALF of the records..

how's this possible .. i thought the "LIKE" and '%%' would minimize my query creation to one single query

or do i need to create every single possible query for each column?(it would be a pain...)

do you have any idea?? on this suggestion and solutions is welcome!! thank you in advance!!!

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 10/03/2013 :  03:24:03  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
You need to look at the data and find out why some rows are being excluded.
Find a row that is missing then run the query on just that row - it should then be obvious what the issue is.
Could it be that nulls are involved? If so just include an "or" part to deal with it in each of your filters.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4613 Posts

Posted - 10/03/2013 :  11:53:27  Show Profile  Reply with Quote
Are any of the columns in your predicate NULLable? If you have NULL values, NULL does not equal any other value (depending on ANSI settings) thus you are not seeing the rows you expected.

Additionally, it looks like you are trying to do a catch-all query anyway, so here is a link that might help you:
http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/
Go to Top of Page

djj55
Constraint Violating Yak Guru

USA
313 Posts

Posted - 10/03/2013 :  13:05:29  Show Profile  Reply with Quote
To show you what Lamprey is talking about try something like:
SELECT BARCODE, ProductCategory, ItemCategory, Brand, Capacity, Interface, Condition, Others, 
    Model, PRODUCT_DESCRIPTION, Quantity, Barcode_Type
FROM Table_Product_Tagging

SELECT BARCODE, ProductCategory, ItemCategory, Brand, Capacity, Interface, Condition, Others, 
    Model, PRODUCT_DESCRIPTION, Quantity, Barcode_Type
FROM Table_Product_Tagging
WHERE   ProductCategory LIKE '%' 

SELECT BARCODE, ProductCategory, ItemCategory, Brand, Capacity, Interface, Condition, Others, 
    Model, PRODUCT_DESCRIPTION, Quantity, Barcode_Type
FROM Table_Product_Tagging
WHERE   ProductCategory LIKE '%' 
    AND ItemCategory LIKE '%' 
.
.
.
and check the number of returned records

djj
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000