I'm trying a simple select statement with variables. If I change the statement like concat_ws('%', @S, '%'); it works fine. to a string. It seems that the select statement does not select the SET variable. Thank you for your help. I am using Mysql80 workbench.
SET @S = "product"; SELECT distinct idproducts FROM mgjtest.vorutaflamedsamheit WHERE productname like concat_ws('%', @S, '%'); ````````````````````````````````````````````````````````````````
Just use
CONCAT
to ensure wildcard characters on both sides of the variable value. Otherwise, first usingCONCAT_WS
as the delimiter argument returns a double wildcard at the end of the string, is equivalent to the single wildcard and produces undesired results.However,
CONCAT
will return wildcards as you would expect: