Click here to Skip to main content
15,665,942 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ON SQL Server

i want to input integer data to table like this 0000001
not 1 as single

can i do that??

1 solution

No. An integer has no concept of leading zeros. If you want to display it as such, then you need to convert it to a string format, either with SQL commands or as part of your display code.
You can brute force it in SQL as:
SELECT RIGHT('000000'+ CONVERT(VARCHAR,myIntColumn),7) AS leadingZeroNumber FROM myTable
But I would probably do it in the presentation layer to ensure the results are source independent.
Share this answer
gunkrr 6-Oct-11 4:03am    
this is my case

Insert into tb_generateid(id,firstname,lastname)
Values('L11'+CAST((@id+1) as varchar(10))+'IVO',@FirstName,@LastName)

i must input @id, but @id is 1 not 0000001
can i create it to be 0000001 ???
OriginalGriff 6-Oct-11 4:46am    
The same RIGHT('000... code will work there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900