如何通过分隔符拆分值?
How to split a value by separator?
我是运行优势数据库10.
我的一个外业数据库有 "customer name",它存储为 "Lastname, FirstName"。我希望能够从该字段中提取名字。我认为这可行,但没有骰子:
SELECT [Customer Name]
,LEFT([Customer Name], CHARINDEX(',', [Customer Name]) - 1) AS [Surname]
,REPLACE(SUBSTRING([Customer Name], CHARINDEX(',', [Customer Name]), LEN([FullName])), ',', '') AS [FirstName]
FROM orders
我没有收到任何结果。这是错误消息:
poQuery: Error 7200: AQE Error: State = S0000; NativeError = 2158; [iAnywhere Solutions][Advantage SQL Engine]Scalar function not found: charindex -- Location of error in the SQL statement is: 57 (line: 2 column: 32)
基本上我会需要
|客户名称 |
母鹿,约翰
成为:
|名字|姓 |
约翰 |母鹿
使用 POSITION(',' IN field)
语法。
在此处查看文档:
http://devzone.advantagedatabase.com/dz/webhelp/Advantage12/master_string_functions.htm
您的查询看起来像这样(未经测试):
SELECT [Customer Name]
,LEFT([Customer Name], POSITION(',' IN [Customer Name]) - 1) AS [Surname]
,REPLACE(SUBSTRING([Customer Name], POSITION(',' IN [Customer Name]), LENGTH([FullName])), ',', '') AS [FirstName]
FROM orders
我是运行优势数据库10.
我的一个外业数据库有 "customer name",它存储为 "Lastname, FirstName"。我希望能够从该字段中提取名字。我认为这可行,但没有骰子:
SELECT [Customer Name]
,LEFT([Customer Name], CHARINDEX(',', [Customer Name]) - 1) AS [Surname]
,REPLACE(SUBSTRING([Customer Name], CHARINDEX(',', [Customer Name]), LEN([FullName])), ',', '') AS [FirstName]
FROM orders
我没有收到任何结果。这是错误消息:
poQuery: Error 7200: AQE Error: State = S0000; NativeError = 2158; [iAnywhere Solutions][Advantage SQL Engine]Scalar function not found: charindex -- Location of error in the SQL statement is: 57 (line: 2 column: 32)
基本上我会需要 |客户名称 | 母鹿,约翰
成为: |名字|姓 | 约翰 |母鹿
使用 POSITION(',' IN field)
语法。
在此处查看文档:
http://devzone.advantagedatabase.com/dz/webhelp/Advantage12/master_string_functions.htm
您的查询看起来像这样(未经测试):
SELECT [Customer Name]
,LEFT([Customer Name], POSITION(',' IN [Customer Name]) - 1) AS [Surname]
,REPLACE(SUBSTRING([Customer Name], POSITION(',' IN [Customer Name]), LENGTH([FullName])), ',', '') AS [FirstName]
FROM orders