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 |
|
M.E.
Aged Yak Warrior
539 Posts |
Posted - 2002-07-31 : 15:30:58
|
| I have no idea why I can't figure this out...strat_unit_age = convert(varchar(5),case when gemm_zone_code_001 = '0' then convert(varchar(5),'00000') else convert(varchar(5),gemm_zone_code_001) end)+ case when gemm_zone_code_002 = '0' then convert(varchar(5),'00000') else convert(varchar(5),gemm_zone_code_002) endthat works fine. What it's doing is setting strat_unit_age = gemm_zone_code_001 + gemm_zone_code_002example:40594 + 39403 = 4059439403The case statement just converts all 0 to 00000... Now to add one last bit on here... Some times the gemm_zone_code_001 returns a values like 8 or 40. These 2 should be padded to 5 chars with 0's... so 00008 instead of 8.I have the feeling this is one of those really simple ones that I just can't see. I'll blame it on the flu I'm recovering from ;)-----------------------Take my advice, I dare ya |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-07-31 : 15:36:11
|
| Any time I need leading zero's on a number I use STR() and REPLACE():SELECT strat_unit_age = Replace(STR(gemm_zone_code_001, 5, 0), ' ', '0') +Replace(STR(gemm_zone_code_002, 5, 0), ' ', '0')FROM myTable |
 |
|
|
M.E.
Aged Yak Warrior
539 Posts |
Posted - 2002-07-31 : 15:50:18
|
damn.. bueatiful rob <--- In that order-----------------------Take my advice, I dare ya |
 |
|
|
|
|
|
|
|