Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Int and leading zeros

Author  Topic 

joemama
Posting Yak Master

113 Posts

Posted - 2005-10-31 : 19:03:56
can anyone tell me how to design a table that has an INT value that keeps the leading zeros???

no if i put in

0003453

i get

3453

thanks

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2005-10-31 : 19:23:53
INT is stored in a 32 bit format internally. It is only the display of the leading zeros that is suppressed.


CODO ERGO SUM
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-10-31 : 20:28:57
Display the necessary leading zeros on the front-end, or use a varchar or char column.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-01 : 23:43:10
>>can anyone tell me how to design a table that has an INT value that keeps the leading zeros???

As said do this in your Presentation Layer.
Where do you want to show this formatted data?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

joemama
Posting Yak Master

113 Posts

Posted - 2005-11-02 : 14:38:58
I want to display the leading zeros on the web..ASP any clues would help???

quote:
Originally posted by madhivanan

>>can anyone tell me how to design a table that has an INT value that keeps the leading zeros???

As said do this in your Presentation Layer.
Where do you want to show this formatted data?

Madhivanan

Failing to plan is Planning to fail

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-11-02 : 16:14:17
Good lord, just give him the answer...


DECLARE @x int
SELECT @x = 0003453
SELECT @x
SELECT RIGHT(REPLICATE('0',7)+CONVERT(varchar(7),@x),7)




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-11-02 : 18:25:03
Display the necessary leading zeros on the front-end, or use a varchar or char column.

That was the correct answer. If the leading zeros are part of the value, they should be stored that way in the database.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

TomG
Starting Member

1 Post

Posted - 2009-11-04 : 06:02:35
SELECT DIGITS(column_name) AS INT FROM Table_name

will also do it....

<removed spam>
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-04 : 06:26:24
'DIGITS' is not a recognized built-in function name.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2009-11-04 : 10:00:31
Thanks for getting back to us 4 years later with the wrong answer.

I believe DIGITS is a DB2 function.



CODO ERGO SUM
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-04 : 10:33:45
quote:
Originally posted by Michael Valentine Jones

I believe DIGITS is a DB2 function.
CODO ERGO SUM




You are CORRECT Sir!



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2009-11-04 : 14:06:34
quote:
Originally posted by X002548

quote:
Originally posted by Michael Valentine Jones

I believe DIGITS is a DB2 function.
CODO ERGO SUM




You are CORRECT Sir!



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



I don't know much about DB2, but I do know Google.







CODO ERGO SUM
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-11-04 : 15:08:26
quote:
Originally posted by Michael Valentine Jones

Thanks for getting back to us 4 years later with the wrong answer.

CODO ERGO SUM



LOL, Too funny
Go to Top of Page
   

- Advertisement -