将一个列拆分为两个?

时间:2017-07-10 07:27:48

标签: sql-server

我正在使用它,

ALTER Table Analytics.dbo.[Parent Table]
ADD [Cost Center] AS Left([Cost Center1], Charindex(':', [Cost Center1])-1)

ALTER Table Analytics.dbo.[Parent Table]
ADD [Project] as Substring([Cost Center1], Charindex(':', [Cost Center1])+1,
              len([Cost Center1])-Len(Charindex(':', [Cost Center1])))

这很有效。但现在的问题是,CostCenter1这一列有很多条目,其中包括' - '而不是'。如何拆分完整列?

2 个答案:

答案 0 :(得分:0)

您可以使用下面给出的代码更新所有数据

<uses-permission android:name="android.permission.CAMERA" />

答案 1 :(得分:0)

ALTER Table Analytics.dbo.[Parent Table] ADD [Cost Center] AS Left([Cost Center1], Charindex(':', REPLACE([Cost Center1],'-',':'))-1) ALTER Table Analytics.dbo.[Parent Table] ADD [Project] as Substring([Cost Center1], Charindex(':', REPLACE([Cost Center1],'-',':'))+1, len([Cost Center1])-Len(Charindex(':', REPLACE([Cost Center1],'-',':')))) 使用REPLACE功能:

P