Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Syntax Help with Group, Sum and dates

Posted on 2011-09-09
3
Medium Priority
?
282 Views
Last Modified: 2012-05-12
I have a MS SQL 2008 Query that I had someone make and I am trying to do a similar query with a different database and I just chaneged the field name.   But it is not working.  The Table is Called Orders and it has two field ChargedTotal and ShippingTotal.  I need a result that if I enter a date range that is will seperate each day out and Sum the totals for that day, or show a Null if nothing.

Here is what I have so far..

SELECT
CONVERT(varchar(6), MakeDates_2.thedate, 101) +
CONVERT(varchar(4), MakeDates_2.thedate, 120) AS DateTime,
CAST(SUM(S.ChargedTotal) AS int) AS ChargedTotal,
ROUND(SUM(S.ShippingTotal), 3) AS ShippingTotal

FROM MakeDates('1/1/2011', '12/23/2011') AS MakeDates_2

LEFT OUTER JOIN (SELECT PaymentReceived, ChargedTotal, ShippingTotal,
CAST(CONVERT(varchar(10), OrderDate, 120) AS datetime) AS DATETIME2

FROM Orders) AS S ON S.PaymentReceived LIKE 'yes' AND S.DATETIME2 = MakeDates_2.thedate
GROUP BY MakeDates_2.thedate
ORDER BY MakeDates_2.thedate

But I get the error:
Msg 208, Level 16, State 1, Line 2
Invalid object name 'MakeDates'.
0
Comment
Question by:Jason Jones
[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 Comments
 
LVL 15

Accepted Solution

by:
pateljitu earned 1000 total points
ID: 36513004
Did you create function MakeDates for this query?
0
 
LVL 14

Assisted Solution

by:Christopher Gordon
Christopher Gordon earned 1000 total points
ID: 36513056
MakeDates appears to be a Table Valued function.  Make sure it exists in your current database and that you prefix it with the correct schema (possibly dbo).
0
 
LVL 1

Author Comment

by:Jason Jones
ID: 36522208
Thanks for the replies, I posted this late Friday and just now back in the office.  I checked and there is a function I forgot to bring over.  Thanks for pointing that out.. how do you guys want me to divvy points?
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

650 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