Skip to Main Content
  • Questions
  • How to zero fill a sum of a count field using SQL

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Michael.

Asked: September 16, 2016 - 6:42 pm UTC

Last updated: September 19, 2016 - 4:40 pm UTC

Version: Version 4.1.2.30

Viewed 1000+ times

You Asked

For two records, this part of the select returns 2, would like to return 000000000000002


(sum(count(distinct(RPAD(to_char(spriden_pidm),15,'000000000000000'))))) Record_count

and Connor said...

Do your formatting LAST, ie

sum(count(distinct(to_char(xxx))))


becomes

to_char(sum(count(distinct(xxx))),'fm0000000000000')



Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Works perfectly!

Michael Calvin, September 19, 2016 - 12:39 pm UTC

This is exactly what I was looking for, thanks!
Connor McDonald
September 19, 2016 - 4:40 pm UTC

glad we could help