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.
| Author |
Topic |
|
jung1975
Aged Yak Warrior
503 Posts |
Posted - 2005-09-19 : 13:01:06
|
| I am trying to convert varchar '0000500' to intbut, it keep truncating the front zeros. How can I keep the front zeros,so it looks like '0000500' not '500' ? |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-09-19 : 13:49:46
|
| In an INT? You can't.You could format the output to a fixed number of places, and thus have "padding" to make up the fixed width, but that's it. An INT is a number, not a formatted numeric representation.What's the problem you are trying to csolve?Kristen |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-20 : 01:17:24
|
| If you want to convert '0000500' to int then both 0000500 and 500 are sameWhy do you need this conversion?Where do you want to use this?MadhivananFailing to plan is Planning to fail |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2005-09-21 : 00:20:18
|
0000500 is not an int. Books Online:quote: int, bigint, smallint, and tinyintExact number data types that use integer data.bigintInteger (whole number) data from -2^63 (-9,223,372,036,854,775,808) through 2^63-1 (9,223,372,036,854,775,807). Storage size is 8 bytes.intInteger (whole number) data from -2^31 (-2,147,483,648) through 2^31 - 1 (2,147,483,647). Storage size is 4 bytes. The SQL-92 synonym for int is integer.smallintInteger data from -2^15 (-32,768) through 2^15 - 1 (32,767). Storage size is 2 bytes.tinyintInteger data from 0 through 255. Storage size is 1 byte.RemarksThe bigint data type is supported where integer values are supported. However, bigint is intended for special cases where the integer values may exceed the range supported by the int data type. The int data type remains the primary integer data type in SQL Server.bigint fits between smallmoney and int in the data type precedence chart. Functions will return bigint only if the parameter expression is a bigint data type. SQL Server will not automatically promote other integer data types (tinyint, smallint, and int) to bigint.
First sentence is key.MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
|
|
|
|
|