Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server / February 2008

Tip: Looking for answers? Try searching our database.

AggregateOfMixedDataTypes error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
p-rat - 28 Feb 2008 17:44 GMT
I have an expression that returns Invoice amounts for the current
month. I try to Sum this though and get the aggregate of mixed data
types error. I've tried to convert the dates, but then get the 'trying
to Sum on data types other than numeric'. Can anyone help me figure
out how I can sum this column? Thank you. This is in Visual Studio on
SQL Server.

= iif(month(InvoiceDate)= month(getdate()) AND year(InvoiceDate)=
year(getdate()), InvoiceAmount, 0)
Roy Harvey (SQL Server MVP) - 28 Feb 2008 22:56 GMT
>I have an expression that returns Invoice amounts for the current
>month. I try to Sum this though and get the aggregate of mixed data
[quoted text clipped - 5 lines]
>= iif(month(InvoiceDate)= month(getdate()) AND year(InvoiceDate)=
>year(getdate()), InvoiceAmount, 0)

This looks like a mix of Access (iif) and SQL Server (getdate()).  You
might want to explain that, and show the entire SELECT with the SUM.

In SQL Server I would write this:

 CASE WHEN month(invoice_date) = month(getdate())
       AND year(invoice_date) = year(getdate())
      THEN InvoiceAmount
      ELSE  0
 END

Note that they type of the constant 0 has to be compatible with the
type of the column InvoiceAmount, and InvoiceAmount has to be a number
that can be SUMmed.

Roy Harvey
Beacon Falls, CT
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.