How to compare if two strings contain the same words in T-SQL for SQL Server 2008?

前端 未结 8 1150
长情又很酷
长情又很酷 2021-01-18 05:22

When I compare two strings in SQL Server, there are couple of simple ways with = or LIKE.

I want to redefine equality as:

If

相关标签:
8条回答
  • 2021-01-18 06:02

    You can add a precomputed column in the base table that is evaluated in INSERT/UPDATE trigger (or UDF default) that splits, sorts and then concatenates words from the original column.

    Then use = to compare these precomputed columns.

    0 讨论(0)
  • 2021-01-18 06:03

    I don't think there is a simple solution for what you are trying to do in SQL Server. My first thought would be to create a CLR UDF that:

    1. Accepts two strings
    2. Breaks them into two arrays using the split function on " "
    3. Compare the contents of the two arrays, returning true if they contain the same elements.

    If this is a route you'd like to go, take a look at this article to get started on creating CLR UDFs.

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