Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 nvarchar is invalid for sum operator

Author  Topic 

tariq2
Posting Yak Master

125 Posts

Posted - 2011-04-08 : 06:04:37
Hi, when I attempt to execute the query I receive the following error. Many thanks in advance..


Msg 8117, Level 16, State 1, Line 2
Operand data type nvarchar is invalid for sum operator.




select
SUM(GBAN01+GBAN02+GBAN03+GBAN04+GBAN05+GBAN06+GBAN07+GBAN08+GBAN09+GBAN10+GBAN11+GBAN12)
FROM

(

select * from openquery(symprod_etldev,'select * from proddta.f0902 where gbmcu = '' 0802378701'' and gblt = ''HA''
AND
(GBAN01+GBAN02+GBAN03+GBAN04+GBAN05+GBAN06+GBAN07+GBAN08+GBAN09+GBAN10+GBAN11+GBAN12)<>0
')
)a
inner join D_Accounts b on a.gbsub = b.L5Sub and a.gbobj = b.L5Account

where b.L1Account in ( '30','40') and b.LEID = '06001'

group by gbsub

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2011-04-08 : 06:43:37
Do all GBAN01 to GBAN12 column have datatype somthing like INT

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

tariq2
Posting Yak Master

125 Posts

Posted - 2011-04-08 : 07:25:12
Yes, these are INT
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-04-08 : 08:39:02
quick and dirty:
quote:
Originally posted by tariq2

Hi, when I attempt to execute the query I receive the following error. Many thanks in advance..


Msg 8117, Level 16, State 1, Line 2
Operand data type nvarchar is invalid for sum operator.




select
SUM(0+GBAN01+GBAN02+GBAN03+GBAN04+GBAN05+GBAN06+GBAN07+GBAN08+GBAN09+GBAN10+GBAN11+GBAN12)
FROM

(

select * from openquery(symprod_etldev,'select * from proddta.f0902 where gbmcu = '' 0802378701'' and gblt = ''HA''
AND
(GBAN01+GBAN02+GBAN03+GBAN04+GBAN05+GBAN06+GBAN07+GBAN08+GBAN09+GBAN10+GBAN11+GBAN12)<>0
')
)a
inner join D_Accounts b on a.gbsub = b.L5Sub and a.gbobj = b.L5Account

where b.L1Account in ( '30','40') and b.LEID = '06001'

group by gbsub




No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

tariq2
Posting Yak Master

125 Posts

Posted - 2011-04-08 : 10:54:33
fantastic :)
Go to Top of Page
   

- Advertisement -