本文介绍了拆分字符串并将其更新为列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,



我有一张名为Customer的桌子,并且提交的姓名是



1. CName

2.联系方式1

3.联系方式2





错误地我们有在

Hello friends,

I have table called Customer and filed names are

1. CName
2. Contact1
3. Contact2


By mistakenly we have entered two contact numbers in

Contact1

列中输入两个联系人号码,其中包含/分隔符。

column with a "/" separator.

Ex:     CName                   Contact1                        Contact2

    1.  Sunil               985456434 / 6786877

    2.  Anil                67574989 / 990756576





现在我想拆分Contact1(985456434/6786877)并将其更新为Contact2列。



如何在SQL中执行此操作... ?



Now i want to split the Contact1(985456434 / 6786877) and update it to Contact2 column.

How can i do it in SQL...?

推荐答案

DECLARE @con1 NVARCHAR(30)

SET @con1 = '67574989 / 990756576'

SELECT CHARINDEX(' ',@con1,1) AS SlashPosition

SELECT RTRIM(SUBSTRING(@con1, 1, CHARINDEX('/',@con1,1)-1)) AS Contact1,
    LTRIM(SUBSTRING(@con1, CHARINDEX('/',@con1,1)+1, LEN(@con1)-CHARINDEX('/',@con1,1))) AS Contact2


这篇关于拆分字符串并将其更新为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 19:34