| Author |
Topic |
|
pazzy11
Posting Yak Master
145 Posts |
Posted - 2007-10-04 : 10:41:48
|
| This code :[CODE]declare @filenumber as charset @filenumber = '65'declare @filenu2 as char(6)set @filenu2 = CONVERT(CHAR(6),(replicate('0',(6-len(@filenumber)))+ @filenumber ))select @filenu2 as x [/CODE]This should return 000065 but it returns 000006i have stepped through it the replicate should replicate the 0 4 times(6 - len of @filenumber) instaed its doing it 5 ?? |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-04 : 10:44:11
|
quote: Originally posted by pazzy11 This code :[CODE]declare @filenumber as char(2)set @filenumber = '65'declare @filenu2 as char(6)set @filenu2 = CONVERT(CHAR(6),(replicate('0',(6-len(@filenumber)))+ @filenumber ))select @filenu2 as x [/CODE]This should return 000065 but it returns 000006i have stepped through it the replicate should replicate the 0 4 times(6 - len of @filenumber) instaed its doing it 5 ??
MadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-04 : 10:44:52
|
| Also if you use front end application, use format function thereMadhivananFailing to plan is Planning to fail |
 |
|
|
pazzy11
Posting Yak Master
145 Posts |
Posted - 2007-10-04 : 10:45:14
|
| what happens if the length of filenumber will vary ? |
 |
|
|
Van
Constraint Violating Yak Guru
462 Posts |
Posted - 2007-10-04 : 10:47:33
|
| Just make it char(25) and be done with it...or char(50) or char(100)...but in this case char(6) would probably be sufficient. |
 |
|
|
pazzy11
Posting Yak Master
145 Posts |
Posted - 2007-10-04 : 11:02:34
|
| ok thanks .. .. AGain !!madhivanan you save me some trouble !! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-05 : 01:56:56
|
quote: Originally posted by pazzy11 ok thanks .. .. AGain !!madhivanan you save me some trouble !!
Weel. You may need to consider this alsodeclare @filenumber as intset @filenumber = 65select right(replicate('0',6)+ cast(@filenumber as varchar(6)),6) as xMadhivananFailing to plan is Planning to fail |
 |
|
|
ranganath
Posting Yak Master
209 Posts |
Posted - 2007-10-05 : 02:43:10
|
| hi,Try This alsoDeclare @x varchar(100)Set @x = '65'Select Replicate ('0', (6-Len(@X)))+ @x |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-05 : 04:12:11
|
quote: Originally posted by ranganath hi,Try This alsoDeclare @x varchar(100)Set @x = '65'Select Replicate ('0', (6-Len(@X)))+ @x
Declare @x varchar(100)Set @x = '6577777'Select Replicate ('0', (6-Len(@X)))+ @xMadhivananFailing to plan is Planning to fail |
 |
|
|
|