Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.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 如何选择在字段的精确位置具有特定值的记录?_Sql_Sql Server_Sql Server 2005_Tsql - Fatal编程技术网

Sql 如何选择在字段的精确位置具有特定值的记录?

Sql 如何选择在字段的精确位置具有特定值的记录?,sql,sql-server,sql-server-2005,tsql,Sql,Sql Server,Sql Server 2005,Tsql,如何选择字段描述第37位的值为“OE”的记录 通过使用此语句,我可以找到所需的记录- select DESC from TABLEA where DESC like '%OE%' 但它也将返回OE位于DESC内其他位置的记录。这将产生不正确的结果 我正在使用MS SQL 2005 select [DESC] from TABLEA where substring([desc], 37, 2) = 'OE' 如果您想在字符串中的某个位置测试两个字符,那么可以使用SUBSTRING

如何选择字段描述第37位的值为“OE”的记录

通过使用此语句,我可以找到所需的记录-

select DESC
from   TABLEA
where  DESC like '%OE%'
但它也将返回OE位于DESC内其他位置的记录。这将产生不正确的结果

我正在使用MS SQL 2005

select [DESC]
from   TABLEA
where  substring([desc], 37, 2) = 'OE'


如果您想在字符串中的某个位置测试两个字符,那么可以使用SUBSTRING函数。

我相信DESC上的子字符串可以帮到您。DESC是一个可怕的列名,因为它是ORDER BY子句中使用的保留字。@mkgiblin很高兴提供帮助!如果这是您的解决方案,请将此标记为答案:
SUBSTRING ( value_expression , start_expression , length_expression )