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.
- Photo Credit Ablestock.com/AbleStock.com/Getty Images
How to Set the Number of Decimal Places to Appear in a Microsoft Access Table Field
You can set the number of decimal places in a MS Access table field to display between 0 and 15 digits. You...
How to Convert Date Format in Transact-SQL
Converting date formats in Transact-SQL is a trivial task when using the supplied functions for datetime-to-character conversion. For nearly all standard date...
How to Convert Only the Date of Datetime
Two date and time fields exist in SQL Server: smalldatetime and datetime. Use one of two functions within Transact-SQL (T-SQL) to extract...