【问题标题】:I cannot understand why charindex is not working我不明白为什么 charindex 不起作用
【发布时间】:2013-10-07 14:07:28
【问题描述】:

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

谁能告诉我原因

   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 是一个 varchar,其中包含 'test\henrov'.....

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

【问题讨论】:

    标签: string tsql function charindex


    【解决方案1】:

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

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

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

    【讨论】:

    • 切弦!总是很有趣^^
    猜你喜欢
    • 2014-04-20
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 2021-10-07
    • 1970-01-01
    相关资源
    最近更新 更多