Best way to compare the end of a string, use RIGHT, LIKE or other?

前端 未结 3 1184
醉梦人生
醉梦人生 2021-02-08 05:17

I need to compare the end of strings against a list of possible ending in a stored procedure. It will be called a lot and there are around 10-15 candidate endings. At this point

相关标签:
3条回答
  • 2021-02-08 06:05

    Parsing strings will have an overhead, best suggestion is the LIKE '%foo' OR as an option. Certain indexes will take advanage and do Seeks over Scans.

    You'd have to benchmark to see if suitable but would be easily testable.

    Check this out regarding LIKE and INDEX http://myitforum.com/cs2/blogs/jnelson/archive/2007/11/16/108354.aspx

    0 讨论(0)
  • 2021-02-08 06:11

    also, you may use a combination of RIGHT and LENGTH so that you do not hardcode string length.

    0 讨论(0)
  • 2021-02-08 06:17

    The best way to optimize this for SQL might be to store the REVERSE string value in another column that is indexed and search the left side of that using either LEFT or LIKE.

    0 讨论(0)
提交回复
热议问题