The forum will be down for maintenance over the weekend of August 18-20, 2017. The forum will be shut down on the evening (EDT) of Friday, August 18. Downtime is unknown but may be up to two days. The forum will be restarted as soon as maintenance is complete.

# How to find the length of a given number ??

 Hi All , Suppose I have a number -- 456712 . I have to get the length as - 6 as it contains 6 digits. Similary If I have a number - 456789098 - Output should be 9. Is there any pre defined function to find out the length. Or else let me know the approach. Thanks, Adithya This question is marked "community wiki". asked 25 Jun '12, 08:25 Adithya 1●1●1●3 accept rate: 0%

 ```SELECT CAST ( 456712 AS INTEGER ) AS x, LENGTH ( STRING ( x ) ) AS "Length of x" UNION SELECT CAST ( 456789098 AS INTEGER ) AS x, LENGTH ( STRING ( x ) ) AS "Length of x" UNION SELECT CAST ( 1000 AS INTEGER ) AS x, LENGTH ( STRING ( x ) ) AS "Length of x" x,Length of x 456712,6 1000,4 456789098,9 ``` answered 25 Jun '12, 08:51 Breck Carter 26.6k●433●604●877 accept rate: 21%
 I got the answer after I thought for a long time. 1> select len(convert(varchar(30),123456)) 2> ``` 6 ``` (1 row affected) Let me know if anything wrong. answered 25 Jun '12, 10:09 Adithya 1●1●1●3 accept rate: 0%
 toggle preview community wiki:

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

Question tags:

×90

question asked: 25 Jun '12, 08:25

question was seen: 929 times

last updated: 25 Jun '12, 10:09