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 & soccer & volleyball' declare @cleanparam varchar(500) select @cleanparam = replace(@myparameter,'&','&') --<----put trick here :) select @cleanparam = replace(@cleanparam,'&','&') select @cleanparam = replace(@cleanparam,'"','"') select @cleanparam = replace(@cleanparam, '©', '©') select @cleanparam = replace(@cleanparam, '«', '«') select @cleanparam
Comments
Post a Comment