Solved

sql sum on nvarchar field

Posted on 2007-12-06
4
1,576 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

710 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