on 2012 Jun 25 9:25 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
67 | |
8 | |
8 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.