|
|
Answers:
By example: declare @Integer int /* Good for positive numbers only. */ select @Integer = 1000
select "Positives Only" = right( replicate("0", 12) + convert(varchar, @Integer), 12)
/* Good for positive and negative numbers. */ select @Integer = -1000
select "Both Signs" = substring( "- +", (sign(@Integer) + 2), 1) + right( replicate("0", 12) + convert(varchar, abs(@Integer)), 12)
select @Integer = 1000
select "Both Signs" = substring( "- +", (sign(@Integer) + 2), 1) + right( replicate("0", 12) + convert(varchar, abs(@Integer)), 12)
go
Produces the following results:
Positives Only -------------- 000000001000
Both Signs ------------- -000000001000
Both Signs ------------- +000000001000
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
There should not be any Spelling Mistakes.
There should not be any Gramatical Errors.
Answers must not contain any bad words.
Answers should not be the repeat of same answer, already approved.
Answer should be complete in itself.
   
|