我需要找出如何编写 T-SQL 来获取数据库中每一行中的第 5 个单词
I need to find out how to code T-SQL that gets the 5th word in each row in a database
确保顺序的一个选项是使用一点 XML
One option which will ensure sequence is to use a bit of XML
示例
Declare @YourTable table (ID int, SomeCol varchar(100))
Insert into @YourTable Values
(1,'Some text that needs to be parsed')
,(2,'Only three words')
Select A.ID
,Pos5 = cast('<x>' + replace(SomeCol,' ','</x><x>')+'</x>' as xml).value('/x[5]','varchar(50)')
From @YourTable A
退货
ID Pos5
1 to
2 NULL
这篇关于T-SQL 获取数据库中每行的第 5 个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
修改现有小数位信息Modify Existing decimal places info(修改现有小数位信息)
多次指定相关名称“CONVERT"The correlation name #39;CONVERT#39; is specified multiple times(多次指定相关名称“CONVERT)
T-SQL 左连接不返回空列T-SQL left join not returning null columns(T-SQL 左连接不返回空列)
从逗号或管道运算符字符串中删除重复项remove duplicates from comma or pipeline operator string(从逗号或管道运算符字符串中删除重复项)
将迭代查询更改为基于关系集的查询Change an iterative query to a relational set-based query(将迭代查询更改为基于关系集的查询)
将零连接到 sql server 选择值仍然显示 4 位而不是concatenate a zero onto sql server select value shows 4 digits still and not 5(将零连接到 sql server 选择值仍然显示 4 位而不是 5)