Click here to Skip to main content
15,943,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a way in SQL to get Sum of column whose datatype is varchar. I tried with Cast method in SQL but it doesn't work. If any body has an idea kindly share with me.
SQL
Query I tried: 

select cast(sum(Total) as int) from tbl_preorder where emailid='xyz@email.com'
Posted
Updated 20-Aug-13 0:59am
v3

Try the other way round:
SQL
SELECT SUM(CAST(Total AS INT)) FROM tbl_preorder WHERE emailid='xyz@email.com'
 
Share this answer
 
Comments
Mas11 20-Aug-13 7:08am    
Thanks !
OriginalGriff 20-Aug-13 7:19am    
You're welcome!
Try this.

SQL
select sum(cast(Total) as int) from tbl_preorder where emailid='xyz@email.com'
 
Share this answer
 
Comments
Mas11 20-Aug-13 7:08am    
Thanks Dear!
SQL
select SUM(CAST(Total AS INT))  from tbl_preorder where emailid='xyz@email.com'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900