【发布时间】:2010-02-19 05:14:34
【问题描述】:
我在一些 sql 中有一些字符串。在给定索引的情况下,我需要找出该字符串的字符是什么。
例如。
DECLARE @someString NVARCHAR(MAX) = 'hi folks'
DECLARE @index INT = 4 -- assuming the first index is 1, not 0.
现在.. 在上面的示例中,我如何在第 4 个索引槽(即“f”)处获取字符。
谢谢:)
【问题讨论】:
我在一些 sql 中有一些字符串。在给定索引的情况下,我需要找出该字符串的字符是什么。
例如。
DECLARE @someString NVARCHAR(MAX) = 'hi folks'
DECLARE @index INT = 4 -- assuming the first index is 1, not 0.
现在.. 在上面的示例中,我如何在第 4 个索引槽(即“f”)处获取字符。
谢谢:)
【问题讨论】:
你可以试试
DECLARE @someString NVARCHAR(MAX) = 'hi folks'
DECLARE @index INT = 4 -- assuming the first index is 1, not 0.
SELECT SUBSTRING(@someString, @index, 1)
【讨论】:
使用SUBSTRING 函数。
SUBSTRING ( value_expression ,start_expression , length_expression )
SELECT SUBSTRING ( @someString, @index, 1);
【讨论】:
使用SUBSTRING:
SELECT SUBSTRING(@someString, @index, 1)
【讨论】: