MS SQLServer 搜索一个值是否包含在其他值中

MS SQLServer Searching to see if a value is contained in other values

我有 Postgre 背景SQL。

如果我想在所有表中的所有列中搜索值中某处包含 "the" 的任何列名,我会这样做:

select *
from information_schema.columns
where column_name ilike '%the%'

这在 SQL Server 2008 R2 中不起作用,有人有什么建议吗?到目前为止,我是 运行 这个查询:

select t.name as table_name, c.name as column_name
from sys.tables as t
inner join
    sys.all_columns as c
on
    c.object_id = t.object_id

where t.name ilike '%the%'

order by c.name, t.name;

where t.name ilike '%the%' 是导致查询失败并显示以下错误消息的原因:

An expression of non-boolean type specified in a context where a condition is expected, near 'ilike'.

有人有什么建议吗?

谢谢

ilike 在sql 服务器中不存在,您可以使用 like 代替。