SQL查询构造-将一列中的数据分为两列 [英] SQL query construction - separate data in a column into two columns

查看:577
本文介绍了SQL查询构造-将一列中的数据分为两列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一列包含链接.问题在于链接的标题在同一列中,因此看起来像这样:
linktitle|-|linkurl
我想要链接标题和链接URL在单独的列中. 我为网址创建了一个新列,因此我正在寻找一种方法来提取它们并使用它们更新linkurl列.有什么聪明的方法来构造一个做到这一点的查询?

I have a column that contains links. The problem is that the titles of the links are in the same column, so it looks like this:
linktitle|-|linkurl
I want link title and linkurl in separate columns. I've created a new column for the urls, so I'm looking for a way to extract them and update the linkurl column with them. Is there any clever way to construct a query that does this?

推荐答案

UPDATE TableName 
SET LinkTitle = Substring(LinkColumn, 0, InStr(LinkColumn, '|-|') - 1),
LinkUrl = Substring(LinkColumn, InStr(LinkColumn, '|-|') + 3)

LinkColumn是当前存在的列,LinkTitle& LinkUrl是您要存储分隔数据的位置.

With LinkColumn being the currently existing column, and LinkTitle & LinkUrl being where you want to store the separated data.

这篇关于SQL查询构造-将一列中的数据分为两列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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