Skip to content
Advertisement

SQL add a * to front and back

Need to add a * to the front and back of the results in order to be able to export it via report builder and use barcodes fonts. Example *1234*

My query is

Select distinct    
    floor(ltrim(rtrim([FGQSHO]))) as QTY,
    ltrim(rtrim([QULOTN])) as Batch,
    floor(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'

My result is

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

I am looking for

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

Advertisement

Answer

Use concat():

Select distinct floor(ltrim(rtrim([FGQSHO]))) as QTY,
       concat('*', ltrim(rtrim([QULOTN])), '*') as Batch,
       concat('*', floor(ltrim(rtrim([QUQTSH]))), '*') as BatchQty
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement