Solved

sql sum on nvarchar field

Posted on 2007-12-06
4
1,568 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
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 insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

809 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