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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to convert varchar certain numeric length?

Author  Topic 

tamancha.1
Starting Member

37 Posts

Posted - 2010-09-23 : 11:49:19
select activity_type, activity_sub_type, sum(revenue)
from #activity_v3
group by activity_type, activity_sub_type

Since revenue is varchar in my database, how do I convert it to numeric to calculate the sum?

I am getting the following error right now:

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

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-09-23 : 12:40:41
Use the CAST or CONVERT functions.

Do you have any data in it that can't be converted though?

And you should work on changing the data type in the table to avoid this issue in the future. Use proper data types.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-09-23 : 13:07:50
why do you have revenue as varchar field?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -