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 |
|
kohlhaas77
Starting Member
25 Posts |
Posted - 2008-07-29 : 10:08:45
|
| I have a question not just about padding an int with zeros (because I think I have that figured out), but I am having trouble getting it to show in the outcome for the following scenario...In this case, I converted the int to a varchar in a SELECT statement for a temp table...SELECT RIGHT(REPLICATE('0', 3)+ CONVERT(VARCHAR(3),A.TimelyFileDays),3) AS TimelyFileDaysINTO #temptableLater, I truncate a table, insert columns back into that table and then do a SELECT statement which includes the TimelyFileDays column...TRUNCATE TABLE MHP001_09_MarketComparisonINSERT INTO MHP001_09_MarketComparison ( TimelyFileDays )SELECT DISTINCT A.TimelyFileDaysThis does not pad the value with zeros as I was hoping, nor will it if I attempt to CONVERT again here.There must be something I am missing from when I create the temp table to when I TRUNCATE and INSERT INTOPlease help! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-29 : 10:15:24
|
| Didnt understand the problem you're facing. Are you asking why 0's were not padded when you inserted to main table from temp table? that is because i guess main table field type is integer. when you populate it with values from temp table which is varchar it gets implicitly converted to integer and hence will drop the 0's towards left side and hence you wont see the 0's |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-29 : 21:40:51
|
quote: INSERT INTO MHP001_09_MarketComparison ( TimelyFileDays )SELECT DISTINCT A.TimelyFileDays
You will need to convert to varchar() again and pad with leading 0 in your select statement EVEN THOUGH you have done it the first time. KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-30 : 02:54:47
|
quote: Originally posted by khtan
quote: INSERT INTO MHP001_09_MarketComparison ( TimelyFileDays )SELECT DISTINCT A.TimelyFileDays
You will need to convert to varchar() again and pad with leading 0 in your select statement EVEN THOUGH you have done it the first time. KH[spoiler]Time is always against us[/spoiler]
Thats true OP cant you do formation at front end application if you use?MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|