Concating multiple value in Sql Query

Posted by Shoyebaziz123 under Sql Server on 4/16/2010 | Views : 1079 | Status : [Member] | Replies : 2
Hi All,
i have written this query

SELECT FGItemId, Convert(char(7),FGFormulaeRM.BatchSize) +'-'+ MasterUnit.Name as BatchName FROM FGFormulaeRM INNER JOIN
MasterUnit ON FGFormulaeRM.BatchUnitId = MasterUnit.UnitId

works correctly

if FGFormulaeRM.BatchSize= 2345.24 and MasterUnit.Name =Kg.

O/P is 2345.24-Kg. Ok...

But
if FGFormulaeRM.BatchSize= 1 and MasterUnit.Name =Kg.

O/P is 1 -Kg.

How i can remove the space Between them showing O/P 1-Kg.

Thanks




Responses

Posted by: Pandians on: 4/16/2010 [Member] [MVP] Silver

Up
0
Down
Hi

Try this....

SELECT FGItemId, REPLACE(Convert(char(7),FGFormulaeRM.BatchSize),' ','') +'-'+ MasterUnit.Name as BatchName FROM FGFormulaeRM INNER JOIN
MasterUnit ON FGFormulaeRM.BatchUnitId = MasterUnit.UnitId

Cheers

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhilan on: 4/20/2010 [Member] Starter

Up
0
Down
use LTRIM and RTRIM function to remove spaces



SELECT FGItemId,LTRIM(RTRIM(Convert(char(7),FGFormulaeRM.BatchSize)) +'-'+ MasterUnit.Name as BatchName FROM FGFormulaeRM INNER JOIN
MasterUnit ON FGFormulaeRM.BatchUnitId = MasterUnit.UnitId



Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response