简体   繁体   中英

how to cast nvarchar to int then add in sql server

i do not understand that what wrong in this query

select cast(B1 as int)+
       (cast(H1 as int)+
       (cast(C1 as int)+
       (cast(I1 as int)) as [man] 
From Kanpur

B1, H1, C1, I1 is declared as nvarchar in database

error: Incorrect syntax near the keyword 'as'.

You are missing the closing parantheses.

select (cast(B1 as int)+cast(H1 as int)+cast(C1 as int)+cast(I1 as int)) as [man]
From Kanpur

Missing parenthesis...write as:

select cast(B1 as int)+
       (cast(H1 as int))+
       (cast(C1 as int))+
       (cast(I1 as int)) as [man] 
From Kanpur

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