如何在SQL Server中分离列数据并将其插入已存在的两个不同的列中 [英] How to seprate Data of Column in SQL Server and insert it into already exist two different column
问题描述
我在数据库中有一个表名 SOURCE ,其中3列名称为 From_Place,To_Place,Area。
From_Place 包含来源地名的名称
To_Place 包括名称目的地Plce名称
区域包括使用'分隔的源位置和目的地位置到''关键字。
我想从列名中分离数据(来源地名和目的地名称) ''区域''并希望插入列 From_Place和To_Place。
帮助我排序这个问题????????
先谢谢。
I have a Table name SOURCE in Database with 3 columns name as From_Place, To_Place, Area.
From_Place Consist the name of Source Place Name
To_Place consist the name of Destination Plce Name
Area consist both source and destinatio place seprated by using ''to'' keyword.
All i want to seprate data(Source Place Name and Destination Place Name) from column name ''Area'' and want to insert into column From_Place and To_Place.
Help me to Sort Out this Problem????????
Thanks in Advance.
推荐答案
检查以下脚本......
Hi,
Check the following Script...
SELECT COALESCE(From_Place,SUBSTRING(Area,1,CHARINDEX(' TO ', Area, 1))) 'From_Place',
COALESCE(To_Place,SUBSTRING(Area,CHARINDEX(' TO ', Area, 1)+4,LEN(Area))) 'To_Place',
NULL Area
FROM SOURCE
问候,
GVPrabu
Regards,
GVPrabu
这篇关于如何在SQL Server中分离列数据并将其插入已存在的两个不同的列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!