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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 searching a sequence of numbers

Author  Topic 

sanjay2988
Starting Member

16 Posts

Posted - 2009-01-07 : 02:14:41
seqNo
1
2
1
2
3
4
5

i 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 field
then use this
declare @seq varchar(32)
select @seq = '5,1,'

select * from urtable where '%,'+ @seq +',%' like '%,'+ cast(seqno as varchar(32)) + ',%'
Go to Top of Page

sanjay2988
Starting Member

16 Posts

Posted - 2009-01-07 : 02:33:29
it is integer field
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-07 : 02:37:51
use this
select * from urtable where '%,'+ @seq +',%' like '%,'+ cast(seqno as varchar(32)) + ',%'
Go to Top of Page

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 expected
expected 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
Go to Top of Page

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 expected
expected 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.
Go to Top of Page
   

- Advertisement -