问题描述
我已经在VB中处理了字符串拆分和稀释计,看起来非常简单直接,但我有点不确定如何在T-SQL脚本中执行它。
我在桌子上有一列信息。我们只有1个可以放入信息,但是目前我们在其中放入了4个不同的信息位,带有' - '分隔符。
我有nfi如何编写脚本来做到这一点。
目前我所拥有的是这个通过MSDN
SELECT来自tillsummaries的SUBSTRING(评论,CHARINDEX('',评论)+ 1,100)
这允许我将一个字符串拆分成一列,但如果我放入下一个我想要分隔的字符串(创建另一个需要条件的select语句),它似乎是在另一个表上创建的。
(我猜这是因为我实际上是在编写两个select语句,所以它们是单独的查询。
如何使用substring函数执行以下操作。
示例信息comment =home-55041213-qld
希望信息保留在一个表中所以它将是
col1 = home,col2 = 55041213 col3 = qld
I've dealt with string splits and dilimeters in VB and seems very easy and straight through, but I'm a little bit unsure as to how to do it within a T-SQL script.
I have a column of information on a table. We only have 1 that we can put information into, but currently we put about 4 different bits of info in it, with a '-' delimiter.
I have nfi how to write the script to do this though.
Currently what I have is this via the MSDN
SELECT SUBSTRING(comment, CHARINDEX('', comment) + 1, 100) from tillsummaries
Which does allow me to split a string into one column, but if I put in the next string that I want to be separated(create another select statement with criteria required), it seems to be created on a different table.
(I'm guessing this is because I am actually writing 2 select statements, so they are separate queries)
How am I able to use the substring function to do the following.
Example info comment = "home-55041213-qld"
would like the information to stay in the one table so it would be
col1 = home, col2 = 55041213 col3 = qld
这篇关于从单个列中拆分一个长字符串中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!