Search code examples
sql-serverexcelvarcharphone-number

Convert ###-###-#### phone number as a string instead of math operation


I have phone number as ###-###-#### in my SQL table. When I export it to CSV file. It shows as turns into a value of the match operation, ie, treating - as a subtract sign.

Also, as an alternative, I can convert ###-###-#### as ##########, ie, removing - how to do that in select query.

Thanks

I tried to cast (phone as varchar) but that didn't help.


Solution

  • Instead of opening the .csv file in Excel, use Excel to import the file. Go to the "Data" ribbon and click the "From Text/CSV" button. Select the file you exported, click the "Load" button and it should import the data from the CSV file with the phone # intact. I ran a test on a .csv file that has phone #s in it and it worked like a charm.