我无法理解为什么charindex不起作用

时间:2013-10-07 14:07:29

标签: string tsql function charindex

我真的很困惑......

有人可以告诉我为什么

   charindex('\', REVERSE('test\henrov')) as char1,
   charindex('\', REVERSE('test\henrov'))-1 as char2,
   len(RIGHT('test\henrov', charindex('\', REVERSE('test\henrov'))))-1 as test,
   right('test\henrov',6) as [OK],
   right('test\henrov', charindex('\', REVERSE('test\henrov'))-1) as [ALSO_OK]

有效,

   charindex('\', REVERSE(m.username)) as char1,
   charindex('\', REVERSE(m.username))-1 as char2,
   len(RIGHT(m.username, charindex('\', REVERSE(m.username))))-1 as test,
   right(m.username,6) as [OK],
   right(m.username, charindex('\', REVERSE(m.username))-1) as [NOT_OK]

不起作用? m.username是一个包含'test \ henrov'的varchar .....

我收到错误:传递给RIGHT函数的长度参数无效。

1 个答案:

答案 0 :(得分:1)

笨!我在这里找到了解决方案:

SQL charindex throwing Invalid length parameter passed to the LEFT or SUBSTRING function because of period?

对(m.username,charindex('\',REVERSE(m.username) +'\')-1)as [OK_Yes]