| Author |
Topic  |
|
|
pushp82
Yak Posting Veteran
67 Posts |
Posted - 05/24/2012 : 05:40:54
|
Hi Friends,
I have a table like: ID VALUES 1 15,14,10 2 4,3,2,1 3 5,6,3,2 -- ----- -- -----
How to select ID which has 2 in VALUES column?
Please try to solve it ASAP as I'm just stuck and watching my monitor for solution.
Thanks in advance. Pushp |
|
|
khtan
In (Som, Ni, Yak)
Singapore
16746 Posts |
Posted - 05/24/2012 : 05:56:38
|
where ',' + VALUES + ',' LIKE '%,2,%'
KH Time is always against us
|
 |
|
|
pushp82
Yak Posting Veteran
67 Posts |
Posted - 05/24/2012 : 06:26:33
|
this will return values for 12 22 as well I need exact actually
ohhh sorry i did not noticed "," after % thanks please help one step more how to pass 2 as parameter? and thanks for this help
quote: Originally posted by khtan
where ',' + VALUES + ',' LIKE '%,2,%'
KH Time is always against us
|
Edited by - pushp82 on 05/24/2012 06:30:38 |
 |
|
|
khtan
In (Som, Ni, Yak)
Singapore
16746 Posts |
Posted - 05/24/2012 : 06:30:55
|
declare @tbl table
(
[ID] int,
[VALUES] varchar(10)
)
insert into @tbl select 1, '15,2,14,10'
insert into @tbl select 2, '12,13,14'
insert into @tbl select 3, '21,22,23'
select *
from @tbl
where ',' + [VALUES] + ',' like '%,2,%'
/* RESULT
ID VALUES
----------- ----------
1 15,2,14,10
(1 row(s) affected)
*/
KH Time is always against us
|
 |
|
|
pushp82
Yak Posting Veteran
67 Posts |
Posted - 05/24/2012 : 06:49:12
|
Ok I was able to do it as :
declare @i int set @i=2 select * from TABLE where VALUES LIKE '%,'+cast(@i as varchar) +',%' or VALUES LIKE cast(@i as varchar) +',%' or VALUES LIKE '%,'+cast(@i as varchar)
thanks |
Edited by - pushp82 on 05/24/2012 06:51:03 |
 |
|
| |
Topic  |
|
|
|