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

Change Css Class of li in ul onclick

Find missing sequence number. Get the numbers where sequence is missing.

Get Query String Values With Javascript