April 3, 2014 at 8:20 am
Hi,
I am using this query to sum two column
REPLACE( CONVERT(VARCHAR(32),cast(round(isnull(sum(R1.[OBM Dollars] + R.[Current Cost]),0),0)as MONEY),1), '.00', '') as [Total Cost],
But I get this error "Operand data type nvarchar is invalid for sum operator"
April 3, 2014 at 8:26 am
vigneshkumart50 (4/3/2014)
Hi,I am using this query to sum two column
REPLACE( CONVERT(VARCHAR(32),cast(round(isnull(sum(R1.[OBM Dollars] + R.[Current Cost]),0),0)as MONEY),1), '.00', '') as [Total Cost],
But I get this error "Operand data type nvarchar is invalid for sum operator"
Pretty clear error message. You can't take a sum of character data. Obviously either OBM Dollars and/or Current Cost is defined as nvarchar.
Why oh why are you storing numeric data in an nvarchar column? And be careful with the MONEY datatype. It can be inaccurate when doing calcuations, especially division or interest calculations.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply