inserting a sum of int fields into a char column

  • I am sum() two interger columns resulting in a number which I than need to insert into a char(7) field. It works with no problem but I am having problems right justifying the results in the char(7) column and padding the left over spaces with 0. For instance, if my sum result is 664, I need to insert the results as 0000664. I can't hard code the zeroes because the sum could 664 or 6640. Any ideas? I thought this would be easy. Maybe not enough sleep.

  • REPLICATE('0',7-LEN(YourResult))+ CAST(YourResult AS VARCHAR)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply