Remove First comma character from string in SQL Server

Last Reply on May 13, 2014 02:30 AM By Azim

Posted on May 13, 2014 02:21 AM

Output as follows

, RFPFF 16, R-AFF 16, RFPFF_C 6

in that above output i want to remove the first comma for that i written query as follows.

My sql query as follows

select substring(ltrim(rtrim(cmn_minor_code,(LEN(cmn_minor_code)))) as Course_Name,cbm_batch_id as Batch_ID from co_batch_master where cbm_active <> 'D' and cbm_batch_start_dt = '01/13/2014' and cmn_minor_code in('RFPFF') 

when i execute shows error as follows The rtrim function requires 1 argument(s). for that how can i write the sql query.

Regards,

Narasiman P.

Posted on May 13, 2014 02:30 AM

Refer this example

DECLARE @Value VARCHAR(200)
SET @Value = ', RFPFF 16, R-AFF 16, RFPFF_C 6'
SELECT LTRIM(SUBSTRING(@Value,2,LEN(@Value)))
-- To see the out put without LTRIM. There will be one space without LTRIM
UNION ALL
SELECT SUBSTRING(@Value,2,LEN(@Value))

Screenshot