此查询一直出错?我无法弄清楚如何正确地写它。
>
附近的语法不正确
CONVERT (
VARCHAR (5000)
, SUBSTRING (
Message
, CHARINDEX ('^14=', Message) + 4
, CHARINDEX ('^', Message, CHARINDEX ('^14=', Message) + 4)
- CHARINDEX ('^14=', Message) - 4,SUBSTRING(
CHARINDEX ('^14=', Message) > 0,
CHARINDEX ('^', Message, CHARINDEX ('^14=', Message) + 4)>0)) AS [ErrorMessage]
答案 0 :(得分:2)
目前还不清楚你要做什么,但你没有正确使用SUBSTRING()
。作为the docs state,此函数为substring(expression, start, length)
。这是你的尝试(向右滚动阅读评论):
CONVERT (VARCHAR (5000)
,SUBSTRING(Message, --expression
CHARINDEX ('^14=', Message) + 4, --start
CHARINDEX ('^', Message, CHARINDEX ('^14=', Message) + 4) - CHARINDEX ('^14=', Message) - 4 --length, needs a ) here to finish the SUBSTRING
,SUBSTRING(CHARINDEX ('^14=', Message) > 0, CHARINDEX ('^', Message, CHARINDEX ('^14=', Message) + 4)>0) --what is this? Starting a new column? Some part of the length arguement of the previous substring?
) AS [ErrorMessage] --closing the COMVERT
您需要解释您为了获得进一步帮助而尝试做些什么。您可能手上有XY Problem。但是,您尝试的核心问题是:
SUBSTRING()
来电CONVERT()
函数