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 2008 Forums
 Transact-SQL (2008)
 multiple Column Query

Author  Topic 

Yonkouturko
Yak Posting Veteran

59 Posts

Posted - 2013-10-02 : 23:07:40
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
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2013-10-03 : 03:24:03
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
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-10-03 : 11:53:27
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

352 Posts

Posted - 2013-10-03 : 13:05:29
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
   

- Advertisement -