• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 864
  • Last Modified:

put 0 in front of integer in sql table field

trying to display 01134214124124 in sql server table field,

it displays 1134214124124

is there ways to configure in table designer to achieve it?
1 Solution
Dale BurrellDirectorCommented:
You might be getting confused between data storage and data display - they are quite different.

If you store a number in SQL Server then you are storing that number - there is no such thing as a leading zero for a number.

When you come to display it you can of course add a leading zero, but you would normally do that in your application code?

If you do need the SQL itself to add a leading zero you need to convert it to a string e.g.

select '0' + convert(varchar(13),MyNum) from (select 1134214124124 MyNum) x

Open in new window

And if you do that you can easily count the number of digits in the number and add a variable number of zeros to the front if that is what you need.
Dave BaldwinFixer of ProblemsCommented:
Dale's right, numbers do not have leading zeros.  Only text displays do that.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now