Invalid length parameter passed to the LEFT or SUBSTRING function error?

huangapple go评论70阅读模式
英文:

Invalid length parameter passed to the LEFT or SUBSTRING function error?

问题

以下是已翻译的内容:

左连接
	WORKQUEUE_INFO wqi
		 wqi.WORKQUEUE_ID = SUBSTRING(hxcmt.hx_comment,CHARINDEX('[',hxcmt.hx_comment)+1,(CHARINDEX(']',hxcmt.hx_comment)-CHARINDEX('[',hxcmt.hx_comment))-1)

HX_COMMENT 返回类似以下数值:

'Deferred until 09/13/2022 12:00 AM CDT on workqueue ADMIN-CATCH ALL QUEUE [203]'

所以,我尝试的是在 HX_COMMENT 中的括号值上进行连接(从上述值中获取的 203)。

有什么原因可能导致这种情况失败?

英文:

I have seen a few of these questions here but can't find something that applies to my code. Here is my snipet where I am getting the error:

left join 
	WORKQUEUE_INFO wqi
		on wqi.WORKQUEUE_ID = SUBSTRING(hxcmt.hx_comment,CHARINDEX('[',hxcmt.hx_comment)+1,(CHARINDEX(']',hxcmt.hx_comment)-CHARINDEX('[',hxcmt.hx_comment))-1)

HX_COMMENT returns values like this:

'Deferred until 09/13/2022 12:00 AM CDT on workqueue ADMIN-CATCH ALL QUEUE [203]'

So what I am trying to do is join on the value in the brackets in HX_COMMENT (203 from the above value)

Any ideas why this might be failing?

答案1

得分: 1

成为一个小问题来陷阱/消除零值

示例

Declare @YourTable Table ([HX_COMMENT] varchar(150))  Insert Into @YourTable Values 
     ('... CDT on workqueue ADMIN-CATCH ALL QUEUE [203]')
    ,('... CDT on workqueue ADMIN-CATCH ALL QUEUE [999] other text')
    ,('... CDT on workqueue ADMIN-CATCH ALL QUEUE -- No Brackets')
     
    
Select A.*
      ,NewVal = substring([HX_COMMENT],P1+1,P2-P1-1)
 From  @YourTable A
 Cross Apply ( values (nullif(charindex('[',[HX_COMMENT]),0),nullif(charindex(']',[HX_COMMENT]),0) ) ) B(P1,P2)

结果

Invalid length parameter passed to the LEFT or SUBSTRING function error?

英文:

It becomes a small matter to trap/nullify zero values

Example

Declare @YourTable Table ([HX_COMMENT] varchar(150))  Insert Into @YourTable Values 
 ('... CDT on workqueue ADMIN-CATCH ALL QUEUE [203]')
,('... CDT on workqueue ADMIN-CATCH ALL QUEUE [999] other text')
,('... CDT on workqueue ADMIN-CATCH ALL QUEUE -- No Brackets')
 

Select A.*
      ,NewVal = substring([HX_COMMENT],P1+1,P2-P1-1)
 From  @YourTable A
 Cross Apply ( values (nullif(charindex('[',[HX_COMMENT]),0),nullif(charindex(']',[HX_COMMENT]),0) ) ) B(P1,P2)

Results

Invalid length parameter passed to the LEFT or SUBSTRING function error?

huangapple
  • 本文由 发表于 2023年3月7日 01:03:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75653743.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定