【问题标题】:select query to retrieve exact word matching from a list of word in mssql选择查询以从 mssql 中的单词列表中检索精确的单词匹配
【发布时间】:2018-03-13 01:30:42
【问题描述】:

[OP 的 403 图像链接]

上图是我在 Mssql 服务器中的数据库表。我想从report_keys 列中选择只包含arrTransactionColumns 的数据。

我的查询是

select * from table where report_keys like '%arrTransactionColumns%'

但它给出的结果也有arrTransactionColumnsHRI

【问题讨论】:

  • USE 等于运算符。为什么要使用 like 运算符?
  • equal to operator 将仅检索 report_key 包含 arrTransactionColumns 的那些行..但我想要所有其中包含 arrTransaction 的行
  • 解释你到底想要什么
  • 这就是您想要的:您希望所有行都具有 arrTransaction。它必须包括 arrTransactionColumns 但避免 arrTransactionColumnsHRI。如果值为 'arrTransactionColu' 是包含还是避免。

标签: sql-server select sql-like


【解决方案1】:

尝试使用CHARINDEX

 select * 
    from TABLE 
    WHERE CHARINDEX('arrTransactionColumns',report_keys )>0

【讨论】:

  • 不能对表或索引视图“ReportColumnTbl”使用 CONTAINS 或 FREETEXT 谓词,因为它不是全文索引。
  • 如果report_key 列仅包含arrTransactionColumnsHRI 怎么办?我想避免report_key 列仅包含arrTransactionColumnsHRI 的行
  • 对于 arrTransactionColumnsHRI,您将获得 0 行
  • 你应该尝试一下。它适用于包含和相等
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-18
  • 1970-01-01
  • 2020-04-21
  • 1970-01-01
  • 1970-01-01
  • 2019-08-09
  • 2021-08-18
相关资源
最近更新 更多