How to Convert a Number to a Varchar in T-SQL


The Transact Structured Query Language (T-SQL) allows you to convert the data type in a database column to a different data type when you move data from one T-SQL object to another object in the T-SQL query. The T-SQL CONVERT function gives you the ability to convert a value of a number variable to the varchar (variable character field) data type. You can use a combination of the CONVERT and CAST functions to limit the decimal points in the original number. By converting the number data columns to the varchar data type, you ensure the proper display of the database data in user applications.

  • Click "Start" in Windows and then click "Microsoft SQL Management Console."

  • Type in the following T-SQL statements in the open window to convert the "test" number variable to the varchar data type with 2 decimal points limit:

    DECLARE @test int

    SELECT @test = 12345

    SELECT REPLACE(CONVERT(varchar(50), CAST(@test AS varchar, 2),'.00','')


  • Click "File" and then click "Save" to apply the change to your database.

Related Searches


  • Photo Credit Images
Promoted By Zergnet


You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!