如何从字符串"text."
获取字符串"This is my text."
?
答案 0 :(得分:7)
SELECT SUBSTRING('This is my text.',CHARINDEX('text.','This is my text.'),5)
如果
Right()
位于字符串的中间,则 text.
将失败。
答案 1 :(得分:6)
SELECT RIGHT('This is my text.',5)
答案 2 :(得分:1)
我假设你想找到“文字”。在表中的任何字符串文字或字段中。这是我的方法(将原始文本返回到搜索,找到要查找的文本,找到的文本的开始位置以及提取的文本):
declare @original varchar(1000), @find varchar(10)
set @original = 'This is my big string and I want to find the word "text" in it.'
set @find = 'text'
select @original as original
, @find as to_find
, charindex(@original, @find) as start_position
, substring(@original, charindex(@find, @original), len(@find)) as extract
当然,如果适用,请将@original替换为您正在搜索的表格中的字段。
答案 3 :(得分:0)
这是一个更普遍问题的具体例子吗? @ KM的回答很滑稽,但我打算说
SELECT 'text'
我猜你是在追求其他东西?
答案 4 :(得分:0)
没有任何帮助,有一个链接here详细说明了这一点。