简体   繁体   中英

convert Varchar to decimal

Can I convert varchar as decimal? I already tried this, but I receive the following error:

"Function argument value, type, or count is invalid"

The column adjust2,tax,sss_ee,sss_er,phic are the columns I'm trying to convert to decimal type.

Dim strQuery As String = "SELECT DATER, CODE, ID, REG_HRS, R_OT, RD_OT, RD_8, HOL_OT," &
         " HOL_OT8, ND, ABS_TAR, ADJUST1, GROSS_PAY, CAST(ADJUST2 AS DECIMAL(10,2)), CAST(TAX AS DECIMAL(10,2))," &
         " CAST(SSS_EE AS DECIMAL(10,2)), CAST(SSS_ER AS DECIMAL(10,2)), CAST(PHIC AS DECIMAL(10,2)), NET_PAY, REG_PAY FROM [" & dbfFileName & "]"

I believe this is data issue, you have existing data that cannot be cast to decimal.

use TRY_PARSE instead.

, COALESCE(TRY_PARSE(ADJUST2 AS DECIMAL(10,2)), 0.00)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM