Here is the query i have written . If input is 'sustainab/ility-en,ergy' then iit should always be populated with the value of TItleDescription with punctuation removed or hyphen replaced by space . so the result should be 'sustainability energy'
But the below query giving me result like 'sustainabilityenergy' How to fix it.
DECLARE @TitleDescription varchar(255) ='sustainab/ility-en,ergy'
DECLARE @RawDescription varchar(255) = @TitleDescription
--'sustainab/ility - en,ergy'
IF (PATINDEX('%[^ 0-9A-Za-z]%', @RawDescription) > 0)
BEGIN
WHILE (PATINDEX('%[^ 0-9A-Za-z]%', @RawDescription) > 0)
BEGIN
SET @RawDescription = TRIM(REPLACE(REPLACE(@RawDescription, SUBSTRING(@RawDescription, PATINDEX('%[^ 0-9A-Za-z]%', @RawDescription), 1), ''), ' ', ' '))
END
END
SELECT @TitleDescription, @RawDescription
Loading
Muhammad Imran AnsariPosted Oct 16, 2024, 12:45 PM
Hi Pinku,
The issue in your query arises because you are removing all non-alphanumeric characters, which leads to joining the words together without spaces. Try the below query, It should work.
Thank you.