Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
My situation is:

col1     col2  
*************
732      abc
732      xyz
732      rrt
6784     rre
6784     oop
56       u7h
56       wwt


I want to list all of col2 which have a part of 732887.
Posted
Updated 13-Mar-15 0:32am
v2
Comments
Shivangi_K 13-Mar-15 6:28am    
do you mean to say that if u give 732887 as input, any value in col1 which has any similarity with the input should be selected? like in this case, abc, xyz, rrt should be selected?
utm 13-Mar-15 6:31am    
yes.

Try below

SQL
declare @t table (col1 varchar(20), col2 varchar(20))
INSERT INTO @t VALUES
('732', 'abc')
,('732', 'xyz')
,('732', 'rrt')
,('6784', 'rre')
,('6784', 'oop')
,('56', 'u7h')
,('56', 'wwt')

SELECT * FROM @t WHERE '732887' LIKE '%' + col1 + '%'
 
Share this answer
 
Comments
utm 13-Mar-15 6:49am    
THANKS ..IT SOLVE MY PROBLEM :)
Try this:
SQL
SELECT * FROM tablename WHERE
CONVERT(VARCHAR, 732887) LIKE '%'+ CONVERT(VARCHAR, col1) +'%'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900