SQL LIKE wildcard space character

前端 未结 9 1256
庸人自扰
庸人自扰 2020-12-19 04:28

let\'s say I have a string in which the words are separated by 1 or more spaces and I want to use that string in and SQL LIKE condition. How do I make my SQL and tell it to

9条回答
  •  轮回少年
    2020-12-19 04:58

    I think that the question is not asking to match any spaces but to match two strings one a pattern and the other with wrong number of spaces because of typos.

    In my case I have to check two fields from different tables one preloaded and the other filled typed by users so sometimes they don't respect 100% the pattern.

    The solution was to use LIKE in the join

       Select table1.field
        from table1
        left join table2 on table1.field like('%' + replace(table2.field,' ','%')+'%')
    

提交回复
热议问题