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
 getting the varchar with specific number of digits

Author  Topic 

j0sh1984
Starting Member

2 Posts

Posted - 2008-11-25 : 21:46:37
Hi there, Is there a way to get the number with datatype varchar with specific number of digits?

This is the following data
70009488494
70009488242
70009482432
32323
94893

what i want to get is the numbers with 11 digits. I will appreciate your help.

pbguy
Constraint Violating Yak Guru

319 Posts

Posted - 2008-11-25 : 22:46:04
select Col1
from @t
where len(cast(col1 as varchar)) >= 11

--------------------------------------------------
S.Ahamed
Go to Top of Page

j0sh1984
Starting Member

2 Posts

Posted - 2008-11-25 : 23:03:37
Thank you So much!!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-25 : 23:11:12
better to specify length while casting to varchar see this

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/12/04/column-length-and-data-length.aspx
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-26 : 02:01:58
or

select Col1
from @t
where col1+0 >= 9999999999


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-11-26 : 02:11:49
quote:
Originally posted by madhivanan

or

select Col1
from @t
where col1+0 >= 9999999999


Madhivanan

Failing to plan is Planning to fail


very lazy


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-26 : 02:22:26
What happens if some record is 11 characters but has non-numeric content?
SELECT	*
FROM Table1
WHERE Col1 LIKE REPLICATE('[0-9]', 11)



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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-26 : 02:30:13
quote:
Originally posted by webfred

quote:
Originally posted by madhivanan

or

select Col1
from @t
where col1+0 >= 9999999999


Madhivanan

Failing to plan is Planning to fail


very lazy


No, you're never too old to Yak'n'Roll if you're too young to die.




Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -