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
 General SQL Server Forums
 New to SQL Server Programming
 LIKE question for querying SKUs

Author  Topic 

lejanco
Starting Member

8 Posts

Posted - 2014-07-09 : 11:37:07
Hello,

I am fairly new to sql and am trying to use it to make my job easier. I am trying to query skus by color, which is the last two digits of their number. Some of the SKUs are 7 digits, some are 5, and some are 9. For example, it their last two digits are 40 I am using this query but it is not working.

Select *
from [TLC New].dbo.TableTop$
Where [Item #] LIKE '%40'

Hopefully a fairly simple problem to solve. Thanks!

Laura Janco

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-07-09 : 11:42:55
That should work if you data type is int or character. - see this example below. If the data type is float, it may not work. Also, if the column has some invisible trailing characters, it would not work. What is the data type of the [Item #] column? Can you post some sample data?
CREATE TABLE #tmp(id INT, x VARCHAR(32));
INSERT INTO #tmp VALUES (40,' 40 '),(40,'40'),(2340,'2340')
SELECT * FROM #tmp WHERE id LIKE '%40'
SELECT * FROM #tmp WHERE x LIKE '%40'

DROP TABLE #tmp
Go to Top of Page

sz1
Aged Yak Warrior

555 Posts

Posted - 2014-07-09 : 11:49:53
Select RIGHT(Item#, 2)
From [TLC New].dbo.TableTop$

We are the creators of our own reality!
Go to Top of Page
   

- Advertisement -