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.
| Author |
Topic |
|
rkumar
Starting Member
3 Posts |
Posted - 2010-09-06 : 02:04:32
|
| TableId Name DivisionId1 Rajeev 2,3,112 Bhashkar 1,5,73 Atul 12,3,11I wanted to search where divisionId is equal to '1'. Can you help me to solve this in single query. Please reply me if you have an idea[b] |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-09-06 : 02:18:16
|
[code]select @divisionid = '1'select *from yourtablewhere ',' + DivisionId + ',' like '%,' + @divisionid + ',%'[/code]You should normalize your table. KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
rkumar
Starting Member
3 Posts |
Posted - 2010-09-06 : 02:49:26
|
quote: Originally posted by khtan
select @divisionid = '1'select *from yourtablewhere ',' + DivisionId + ',' like '%,' + @divisionid + ',%' You should normalize your table. KH[spoiler]Time is always against us[/spoiler]Thanks It's working.My database is normalize and I am searching on temporary tables created in procs.
|
 |
|
|
sanjayguptag
Starting Member
1 Post |
Posted - 2010-09-06 : 07:20:49
|
| Try to use following....select *from #tmp where DivisionId like '1,%' and ( DivisionId not like '%[1-9]1' and DivisionId not like '%1[1-9]' or DivisionId like '%,1,%' or DivisionId like '%,1%' ) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-09-06 : 08:37:33
|
quote: Originally posted by sanjayguptag Try to use following....select *from #tmp where DivisionId like '1,%' and ( DivisionId not like '%[1-9]1' and DivisionId not like '%1[1-9]' or DivisionId like '%,1,%' or DivisionId like '%,1%' )
Dont complicate it. See what khtan postedMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|