分割函数出现错误
下面的代码我用于 MSSQL 2005,但是当我尝试在 MSSQL 2000 中运行时,我遇到了以下错误。
Msg 156, Level 15, State 1, Procedure StrSplit, Line 5
Incorrect syntax near the keyword 'WITH'.
Msg 170, Level 15, State 1, Procedure StrSplit, Line 15
Line 15: Incorrect syntax near ')'.
CREATE FUNCTION dbo.StrSplit (@sep char(1), @s varchar(512))
RETURNS table
AS
RETURN (
WITH Pieces(pn, start, stop) AS (
SELECT 1, 1, CHARINDEX(@sep, @s)
UNION ALL
SELECT pn + 1, stop + 1, CHARINDEX(@sep, @s, stop + 1)
FROM Pieces
WHERE stop > 0
)
SELECT pn,
SUBSTRING(@s, start, CASE WHEN stop > 0 THEN stop-start ELSE 512 END) AS s
FROM Pieces
)
提前致谢
Below code i am using for MSSQL 2005,but when i try to run in MSSQL 2000 i am getting below erros.
Msg 156, Level 15, State 1, Procedure StrSplit, Line 5
Incorrect syntax near the keyword 'WITH'.
Msg 170, Level 15, State 1, Procedure StrSplit, Line 15
Line 15: Incorrect syntax near ')'.
CREATE FUNCTION dbo.StrSplit (@sep char(1), @s varchar(512))
RETURNS table
AS
RETURN (
WITH Pieces(pn, start, stop) AS (
SELECT 1, 1, CHARINDEX(@sep, @s)
UNION ALL
SELECT pn + 1, stop + 1, CHARINDEX(@sep, @s, stop + 1)
FROM Pieces
WHERE stop > 0
)
SELECT pn,
SUBSTRING(@s, start, CASE WHEN stop > 0 THEN stop-start ELSE 512 END) AS s
FROM Pieces
)
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用以下函数代替它。
希望这有帮助!
Use the below function in its place.
Hope this helps!!
CTE - IE“WITH”是从 sql 2005 开始的一项功能。2000 年不可用...
CTE's - IE "WITH" are a feature starting in sql 2005. Not available in 2000...
您不能使用 CTE(通用表表达式 -
WITH) 在 SQL Server 2000 中。它们是在 SQL Server 2005 中引入的。
You cannot use CTE's (Common Table Expressions -
WITH
) in SQL Server 2000. They were introduced in SQL Server 2005.