Solved

sql sum on nvarchar field

Posted on 2007-12-06
4
1,563 Views
Last Modified: 2008-02-01
I have a table that is labeled as a nvarchar and it contains only numbers, I want to do a query like below (sum) but I get error because its a nvarchar field.

select sum(startingbid) as totalvaue from items

The sum or average aggregate operation cannot take a nvarchar data type as an argument.

changing the column to an int is not an option...
0
Comment
Question by:lobos
  • 3
4 Comments
 
LVL 29

Accepted Solution

by:
Nightman earned 25 total points
Comment Utility
select sum(cast(startingbid as int)) as totalvaue from items
0
 
LVL 29

Expert Comment

by:Nightman
Comment Utility
Note: if there are any non-numeric characters in this field, you will get an error. You really need to move towards storing your data in the correct type.
0
 

Author Comment

by:lobos
Comment Utility
I understand this, but this has gone live already and there is not much of a choice, plus this is just a pilot project...
turns out...int wont work because there are decimal values....
so change I just int to decimal and it will be good?
0
 
LVL 29

Expert Comment

by:Nightman
Comment Utility
Yes, that would work fine.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now