In printing out some calculated values that involve division to calculate a percentage I’m receiving a divide by zero error. I’m not worried that it is happening, I just want to know how I can print a 0 along with the rest of the line instead of it printing the error, ie 0%.
This is my print statement:
print cast(@usercode as varchar) + ' ' + @username + space(4) +
'cr' + space(4) + cast(@totalUserVolumeCredit as varchar) +
space(4) + cast(@userUnpaids as varchar) + space(4) +
cast(@userDisputes as varchar) + space(4) +
cast((@userUnpaids + @userDisputes) as varchar) + space(4) +
cast(((@userUnpaids + @userDisputes)/@totalUserVolumeCredit) as varchar) + --error line
space(4) + cast(@userRedirectsVolume as varchar);
Demo