Solved

put 0 in front of integer in sql table field

Posted on 2014-03-16
2
786 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
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DTS Connection Failed 7 70
query execution hang 5 32
2016 SQL Licensing 7 41
Weighted Randomizing 6 16
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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.
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.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

831 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