Question

I am truly baffled......

Can someone tell me why

   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]

works and

   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]

does NOT work? m.username is a varchar that contains 'test\henrov'.....

I get an error: Invalid length parameter passed to the RIGHT function.

Was it helpful?

Solution

Stupid! I found the solution here:

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]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top