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 |
|
sanjay2988
Starting Member
16 Posts |
Posted - 2009-01-07 : 02:14:41
|
| seqNo 1 2 1 2 3 4 5i want to search whether 1,2,3 appear in a sequence or not in a column. i am looking for a pattern occurance.. |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-07 : 02:24:48
|
| if seqno is int fieldthen use thisdeclare @seq varchar(32)select @seq = '5,1,'select * from urtable where '%,'+ @seq +',%' like '%,'+ cast(seqno as varchar(32)) + ',%' |
 |
|
|
sanjay2988
Starting Member
16 Posts |
Posted - 2009-01-07 : 02:33:29
|
| it is integer field |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-07 : 02:37:51
|
| use thisselect * from urtable where '%,'+ @seq +',%' like '%,'+ cast(seqno as varchar(32)) + ',%' |
 |
|
|
sanjay2988
Starting Member
16 Posts |
Posted - 2009-01-07 : 02:51:01
|
| declare @seq varchar(32)select @seq = '3,5'select * from temp1 where '%,'+ @seq +',%' like '%,'+ cast(seqno as varchar(32)) + ',%'i run above query and output i got is 3,5 but not expectedexpected is this should give me false because 4 comes in between them. only if they occurs one after the other it should give me true |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-07 : 03:16:52
|
quote: Originally posted by sanjay2988 declare @seq varchar(32)select @seq = '3,5'select * from temp1 where '%,'+ @seq +',%' like '%,'+ cast(seqno as varchar(32)) + ',%'i run above query and output i got is 3,5 but not expectedexpected is this should give me false because 4 comes in between them. only if they occurs one after the other it should give me true
as told before you should have an id column or some other fiel to check the sequence in your table. |
 |
|
|
|
|
|
|
|