tsql - Trying to find substring in string on sql server -


i have read in many articles , including here on stackoverflow find substring following should used:

if charindex('myword', @words) > 0 begin     -- end 

i trying following it's not working returns wrong:

say have string 'basketball & soccer', trying write script checks ampersand , encodes & becomes 'basketball & soccer' problem there may 1 in database 'basketball & soccer'.

so when run script, second 1 becomes:

'basketball & soccer' 

i trying following clean it:

declare @cleanparam varchar(500)     if charindex('&',@myparameter) > 0  begin     -- if & in string skip , start quotes    select @cleanparam = replace(@myparameter,'"','"')    end else  begin       -- if not clean &'s , quotes , continue others       select @cleanparam = replace(@myparameter,'&','&')          select @cleanparam = replace(@cleanparam,'"','"')     end        select @cleanparam = replace(@cleanparam, '©', '©')       select @cleanparam = replace(@cleanparam, '«', '«')         -- others here 

try this

declare @myparameter varchar(500)  set @myparameter = 'basketball &amp; soccer & volleyball'   declare @cleanparam varchar(500) select @cleanparam = replace(@myparameter,'&amp;','&') --<----put trick here :) select @cleanparam = replace(@cleanparam,'&','&amp;')    select @cleanparam = replace(@cleanparam,'"','&quot;')  select @cleanparam = replace(@cleanparam, '©', '&copy;') select @cleanparam = replace(@cleanparam, '«', '&laquo;')   select @cleanparam 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -