SQL Multiple LIKE Statements

后端 未结 3 1456
夕颜
夕颜 2020-12-11 04:22

I\'m currently working on a report that shows me all post codes covered by our sales team.

Each team covers over 100 post codes. What i would like to do is create a

3条回答
  •  天涯浪人
    2020-12-11 04:44

    One of possible solutions. Create a table Prefix(v varchar(4)) where you insert those values. Then a solution would be:

    SELECT * 
    FROM tbl_ClientFile cf
    JOIN Prefix p on cf.CLNTPOST1 LIKE p.v + '%'
    

    To exclude duplicates if some prefix includes some another prefix like BB1, BB10, BB15...:

    SELECT DISTINCT cf.* 
    FROM tbl_ClientFile cf
    JOIN Prefix p on cf.CLNTPOST1 LIKE p.v + '%'
    

提交回复
热议问题