Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL Server 2008:在包含单词World的表中查找字符串_Sql_Database_Sql Server 2008 - Fatal编程技术网

SQL Server 2008:在包含单词World的表中查找字符串

SQL Server 2008:在包含单词World的表中查找字符串,sql,database,sql-server-2008,Sql,Database,Sql Server 2008,我试图过滤我的查询,以仅显示单词WORLD的表条目,并包含其他国家/地区代码 我使用了通配符函数,但我不确定如何让它只返回带有世界和其他国家代码的条目 SELECT * FROM [****].[dbo].[Titles] WHERE Territories LIKE '%world%' 谢谢你的帮助 编辑:预期结果将返回字段中包含世界和一个或多个国家代码的所有行。此表中的“地区”列包含世界或国家代码,并且应同时包含这两个代码。我运行此查询的原因是要搜索任何包含错误数据的行。如果它可以包含其他

我试图过滤我的查询,以仅显示单词WORLD的表条目,并包含其他国家/地区代码

我使用了通配符函数,但我不确定如何让它只返回带有世界和其他国家代码的条目

SELECT *
FROM [****].[dbo].[Titles]
WHERE Territories LIKE '%world%'
谢谢你的帮助


编辑:预期结果将返回字段中包含世界和一个或多个国家代码的所有行。此表中的“地区”列包含世界或国家代码,并且应同时包含这两个代码。我运行此查询的原因是要搜索任何包含错误数据的行。

如果它可以包含其他国家代码和世界,那么您需要

WHERE Territories LIKE '%world%' AND Territories LIKE '%{other country code}%'
如果您正在查看您需要的世界或其他国家代码

WHERE Territories LIKE '%world%' OR Territories LIKE '%{other country code}%'

如果它可以包含其他国家代码和世界代码,那么您需要

WHERE Territories LIKE '%world%' AND Territories LIKE '%{other country code}%'
如果您正在查看您需要的世界或其他国家代码

WHERE Territories LIKE '%world%' OR Territories LIKE '%{other country code}%'

你可以试试这样的

SELECT *
FROM [****].[dbo].[Titles]
WHERE Territories LIKE '%world%'
AND Territories LIKE '%countryCode%'
SELECT *
FROM [****].[dbo].[Titles]
WHERE Territories LIKE '%world%countryCode%'
但我不确定这会有多快。如果你知道其他国家代码总是在世界代码之后,你可以这样做

SELECT *
FROM [****].[dbo].[Titles]
WHERE Territories LIKE '%world%'
AND Territories LIKE '%countryCode%'
SELECT *
FROM [****].[dbo].[Titles]
WHERE Territories LIKE '%world%countryCode%'

我认为应该跑得更快。

你可以试试这样的东西

SELECT *
FROM [****].[dbo].[Titles]
WHERE Territories LIKE '%world%'
AND Territories LIKE '%countryCode%'
SELECT *
FROM [****].[dbo].[Titles]
WHERE Territories LIKE '%world%countryCode%'
但我不确定这会有多快。如果你知道其他国家代码总是在世界代码之后,你可以这样做

SELECT *
FROM [****].[dbo].[Titles]
WHERE Territories LIKE '%world%'
AND Territories LIKE '%countryCode%'
SELECT *
FROM [****].[dbo].[Titles]
WHERE Territories LIKE '%world%countryCode%'

我认为应该运行得更快。

您能发布示例数据和预期结果吗?国家代码是另一列吗?请发布您的表架构。Territions列中可能的值是什么?请举例说明你想选择什么和不应该选择什么。你能公布样本数据和预期结果吗?国家代码是另一列吗?请发布您的表架构。Territions列中可能的值是什么?请举例说明你想选什么和不应该选什么。我同意,如果你知道它们在后面,并且不是相互排斥的,那会更快。我同意,如果你知道它们在后面,并且不是相互排斥的,那会更快。