Tuesday, March 24, 2015

Integer to String in SQL Server

A Frequent question for in SQL Server Interviews is how to convert integer to string. Generally it confuses us even we know the answer but putting it into syntax is difficult.

below are few ways which you can memorize for interview ;) 

DECLARE @i int
SET @i=98235

-- Firs Ways - Use CAST function
SELECT CAST(@i as varchar(10))

-- Second Way --> Use CONVERT function
SELECT CONVERT(varchar(10),@i)

--Third Way : Use STR function
SELECT LTRIM(STR(@i,10))

No comments:

Post a Comment