Solved

sql sum on nvarchar field

Posted on 2007-12-06
4
1,565 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
ID: 20421991
select sum(cast(startingbid as int)) as totalvaue from items
0
 
LVL 29

Expert Comment

by:Nightman
ID: 20421996
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
ID: 20422097
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
ID: 20422102
Yes, that would work fine.
0

Featured Post

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

867 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

19 Experts available now in Live!

Get 1:1 Help Now