• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1595
  • Last Modified:

sql sum on nvarchar field

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
lobos
Asked:
lobos
  • 3
1 Solution
 
NightmanCTOCommented:
select sum(cast(startingbid as int)) as totalvaue from items
0
 
NightmanCTOCommented:
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
 
lobosAuthor Commented:
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
 
NightmanCTOCommented:
Yes, that would work fine.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now