sql server - Error converting data type varchar to numeric when converting substring to decimal -




i have table includes varchar column populated values

employee not entitled ssp because average weekly earnings below lel.average earnings: £44.13750

enter image description here

i trying extract value after £ sign have tried:

select      clientid     , max(payperiod) periodno , case when max(comment) '%£%'      cast(max(right(comment, charindex('£', reverse(comment))-1) )as decimal(5,2))      else 0 end avgearnings2            t_payrollsspemployeecomment       comment '%lel%' , comment '%£%'         group              clientid 

i want retrieve value can cast decimal 110.25

but getting error

error converting data type varchar numeric. 

i can value or without £ sign, need cast right number of decimal places report. doing wrong here?

can try this, substring function can used extract number after character £.

    select      clientid     ,max(payperiod) periodno     ,case when max(comment) '%£%'            cast(substring(max(comment),2,len(max(comment))) decimal(18,2))         else 0 end avgearnings2           t_payrollsspemployeecomment      comment '%lel%' , comment '%£%'      group clientid 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

python - Read npy file directly from S3 StreamingBody -