Search

Showing posts with label Integer to String. Show all posts
Showing posts with label Integer to String. Show all posts

Tuesday, January 11, 2011

Convert Integer to String in SQL Server

A very frequently asked question is how to convert an Integer to String in SQL Server. Here are 3 different ways of doing the same task:
DECLARE @i intSET @i=98235
--Method 1 : Use CAST function
SELECT CAST(@i as varchar(10))
--Method 2 : Use CONVERT function
SELECT CONVERT(varchar(10),@i)
--Method 3 : Use STR function
SELECT LTRIM(STR(@i,10))