Link to home
Start Free TrialLog in
Avatar of baylar
baylar

asked on

sql left and charindexfunction

Can anyone please tell why this is erroring out

select            
case  
when isnumeric(left('2022AVEQENSLEY',case when charindex(char(32),'2022AVEQENSLEY')
            =0 then 2
            else charindex(char(32),'2022AVEQENSLEY') end -1)) = 1
then left('2022AVEQENSLEY',charindex(char(32),'2022AVEQENSLEY')-1)
else replace(replace('2022AVEQENSLEY',char(32),''),'.','')
end
      
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image


This returns 0
charindex(char(32),'2022AVEQENSLEY')

Then you actually reduce it by -1
else charindex(char(32),'2022AVEQENSLEY') end -1))

You can not pass -1 to CHARINDEX function
ASKER CERTIFIED SOLUTION
Avatar of QPR
QPR
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of baylar
baylar

ASKER

Awesome works the way I want.
Thanks