sqlsql-server

replace or remove characters and then cast to decimal


I need to remove or replace an unwanted character (%) which is at the end of a string and then to cast the string to a decimal, because I need to get the sum of 2 fields named discount1 and discount2

The last combination I tried is:

replace ((p16.pa_value,'%','')CAST (p16.pa_value AS DECIMAL (3,0))) as discount2,

It seems to be super wrong as the CAST is inside of the replace statement


Solution

  • try this:

    CAST (replace (p16.pa_value,'%','') AS DECIMAL (3,0)) as discount2