简体   繁体   中英

Arithmetic overflow error converting varchar to data type numeric -error

I am trying to concat the following columns

c.coursec + ' ' +  ms.sectionn, 

ms.secitonn is a (decimal 3,0)

Thus I am getting an error:

Arithmetic overflow error converting varchar to data type numeric.

c.coursec = 187C
ms.sectionn = 2
needed results is 187c-2 

I assume I must do some kind of cast or convert?

You are correct, a convert will allow your string to concatenate.

c.coursec + ' ' +  Convert(varchar(50), ms.sectionn), 

Cast is valid as well:

c.coursec + ' ' +  CAST( ms.sectionn AS varchar(50)), 

Depending on the type of c.coursec you'll want to adjust your convert parameter. For example if c.coursec is nvarchar then modifying the cast would be appropriate.

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