SQL Server formatting negative values from selected data -


i new stackoverflow search often.

i creating report data in have format negative numbers like,

-00000010  (9 characters max) 

i getting this, 000000-10

this attempting i'm having issues. appreciated.

select 'h'      + dg.block      + left(dg.zip,5)      + right('000000000'      + cast(cast(sum(dg.wp)as int) varchar(9)),9)      + right('000000000' + cast(cast(sum(dg.we)as int) varchar(9)),9)     + right('000000000' + cast(cast(sum(dg.ep)as int) varchar(9)),9)      + right('000000000' + cast(cast(sum(dg.ee)as int) varchar(9)),9)     + right('000000000' + cast(cast(count(dgg.claimcontrol)as int) varchar(9)),9)     + right('000000000' + cast(cast(sum(dgg.inc) int) varchar(9)),9)     + right('000000000' + cast(cast(sum(dgg.paid)as int) varchar(9)),9)     + right('000000000' + cast(cast(sum(dgg.alae) int) varchar(9)),9)  [h record] table 

if 2012+, have option of format().

example

select replace(format(-1,' 000000000'),'- ','-') 

returns

-000000001  if number negative  000000001  if number positive 

just word of caution. format() has great functionality, not known high performer.


Comments

Popular posts from this blog

angular - DownloadURL return null in below code -

python 2.7 - Given three nested dictionaries, sort the top two nested dictionaries from a value in the innermost dictionary? -