How to convert int to varchar in SQL Server without deleting zero value?
For example this query
Select CONVERT(varchar,002000089) results in:
2000089 How can I get 002000089 as the query result?
I have two way to get the result 002000089 in sql-server
00 + CONVERT(varchar,002000089)declare @intValue int=002000089 select '00'+ convert(varchar,@intValue) 000000000 by stuffdeclare @intValue int=002000089 declare @metaValue varchar(20)='000000000' print stuff( @metaValue, len(@metaValue)-len(@intValue)+1, len(@intValue), cast(@intValue as varchar))
002000089isn't an int, an int can't have preceding zero's. So you're trying to convert a string to a string.intvariable/column, which is designed for storing numbers.