Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a legacy table with a phone number as FLOAT. I would like to convert it to VARCHAR. Example:
SQL
SELECT
    [PhoneNumber01] AS FloatPhone,
    CONVERT(varchar(50), PhoneNumber01, 2) AS ConvertPhone,
    CAST([PhoneNumber01] AS VARCHAR(15)) AS CastPhone
FROM OurTable

with the output of:
<text>
FloatPhone ----- ConvertPhone --------------- CastPhone
9995553605 ---- 9.995553605000000e+009 ---- 9.99555e+009

Is there a one step solution or do I need to use string manipulation to remove extras (scientific notation)?

Thanks
djj
Posted

1 solution

Dear u can use replace and rtrim combination. surely this problem will resolve...

Thanks
 
Share this answer
 
Comments
Corporal Agarn 28-Jul-11 9:45am    
I was looking for a one function answer, however I had done what you suggested:
REPLACE(LEFT(CONVERT(varchar(50), PhoneNumber01, 2), 11), '.', '')

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900