EmersonH.Com

Transforming Knowledge into Power

  • Increase font size
  • Default font size
  • Decrease font size
Home T-Sql how to convert a number to string in SQL

how to convert a number to string in SQL

E-mail Print

The best place to do such formatting is in the front end, not at the database level.

That being said, you could use a combination of the CONVERT and CAST functions (see CAST and CONVERT) to cast the number as a money type, then convert it to a varchar, and then strip off the decimal point and 2 0's at the end:
DECLARE @test int
SELECT @test = 12345
SELECT REPLACE(CONVERT(varchar(50), CAST(@test AS money), 1),'.00','')