Remove Extra Commas From Beginning or Ending of a String


A simple and very short code to replace extra commas from the beginning or ending of a string. No need to explain the code.

DECLARE @str VARCHAR(50) = ',a,n,i,s,h,'

SELECT @str

SET @str = REPLACE(@str, ',', ' ')
SET @str = LTRIM(RTRIM(@str))

SELECT  REPLACE(@str,' ', ',')

Comments

Popular posts from this blog

Get Query String Values With Javascript

Change Css Class of li in ul onclick

Change Text Color with Javascript