从单个列中拆分一个长字符串中的字符串 [英] Split strings out of one long string from a single column

查看:74
本文介绍了从单个列中拆分一个长字符串中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在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

解决方案

检查这个链接我认为它可以帮到你很多





http://social.technet.microsoft.com/wiki/contents/articles/26937.t-sql-splitting-a-string-into-multiple-columns.aspx [ ^ ] 4

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

解决方案

CHECK THIS LINK I THINK IT HELPS YOU A LOT


http://social.technet.microsoft.com/wiki/contents/articles/26937.t-sql-splitting-a-string-into-multiple-columns.aspx[^]4


这篇关于从单个列中拆分一个长字符串中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆