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
 General SQL Server Forums
 New to SQL Server Programming
 how to wildcard random numbers?

Author  Topic 

seniorito410
Starting Member

2 Posts

Posted - 2010-09-01 : 21:33:34
i have this table which contains sources, and im going to create a gode which will display the sources which have numbers with more than 4 digits.
Is there a way to filter a value if a column if there are more than 4 digits in it? this would mean any number with more than 4 digits
e.g.
assume that this is a value in a column:
"there are 983467 people in the plaza."

only the records with more than 4digits in it , we've tried the '%[1-9]%', but i think the '[]' doesnt work

*edited*

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-09-01 : 23:26:18
Try this:



Declare @STemp table
(Val int)

Insert into @sTemp
Select 253695 union
select 123 union
select 14751


--If it is numeric field like integer.
select * from @stemp where len(val) >4

--When there is character between digits
select * from @stemp where val like '%[0-9]%[0-9]%[0-9]%[0-9]%'

--When all digits are next to each other
select * from @stemp where val like '%[0-9][0-9][0-9][0-9]%'


Regards,
Bohra

I am here to learn from Masters and help new bees in learning.
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-09-02 : 02:32:41
Oh come on! Any number having more than 4 digits is greater than 9999! select * from @stemp where val > 9999

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

seniorito410
Starting Member

2 Posts

Posted - 2010-09-02 : 03:49:54
@lumbago
ikr but the problem is the column is not numeric, it a clob data type

@bohra
thanks for the help :)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-09-02 : 04:04:10
WHERE Col1 LIKE '% [1-9][0-9][0-9][0-9][0-9]%'


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -