Skip to content
Advertisement

SQL remove leading zeros

I am unable to remove the leading zeros from a column. In this case my SQL query is

Select distinct 


ltrim(rtrim([FGQSHO])) as QTY,
ltrim(rtrim([QULOTN])) as Batch,
ltrim(rtrim([QUQTSH])) as BatchQty

FROM serh

left join boll on serh.HVSERN = boll.QUSERN
left join bold on boll.QUBOL# = bold.FGBOL# and boll.QUENT# = bold.FGENT#
left join bolh on bold.FGBOL# = bolh.FEBOL#
left join ocri on bold.fgord# = ocri.ddord# and bold.fgitem = ocri.dditm#

where FGBOL# = '761221'

The result is

   QTY           Batch          BatchQty
30.00000    4615J0003  3Q20     14.00000
30.00000    4615J0005  4Q20     16.00000

I am looking for this result.

QTY           Batch            BatchQty
30         4615J0003  3Q20        14
30         4615J0005  4Q20        16

Advertisement

Answer

Use the floor() function:

floor(ltrim(rtrim([FGQSHO]))) as QTY,

Why are you storing these values as strings in the first place? You should be storing numbers as numbers. And if they are numbers, you should not be using string functions on them.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement