Solved

put 0 in front of integer in sql table field

Posted on 2014-03-16
2
803 Views
Last Modified: 2014-03-16
trying to display 01134214124124 in sql server table field,

it displays 1134214124124

is there ways to configure in table designer to achieve it?
0
Comment
Question by:doramail05
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 500 total points
ID: 39933301
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.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39933414
Dale's right, numbers do not have leading zeros.  Only text displays do that.
0

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question