uld like to create a function to sum up total order amount within the date range, but i don't know how to write the right query. The query below is for counting the total orders, but I want to change to sum up total order amount. The Database table is attached. Please assist. ************************************** USE SQLBook; DROP FUNCTION IF EXISTS GetDateRangewithordersAmount GO

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question
100%

I would like to create a function to sum up total order amount within the date range, but i don't know how to write the right query. The query below is for counting the total orders, but I want to change to sum up total order amount.

The Database table is attached.

Please assist.

**************************************

USE SQLBook;

DROP FUNCTION IF EXISTS GetDateRangewithordersAmount
GO

CREATE FUNCTION GetDateRangewithordersAmount
(   
    @startDate DateTime,
    @endDate DateTime
)
RETURNS TABLE 
AS
RETURN 
(
    
select [State], count (*) as [TotalOrderAmount]
   FROM [SQLBook].[dbo].[Orders]
   WHERE [OrderDate] between @startDate AND @endDate
   group by [State]
)
GO

SELECT * FROM GetDateRangewithordersAmount('2015-09-01','2015-10-31');
GO

|Customer Campai OrderDate
City
ZipCod - Payme - TotalPrice - NumUnits
NumOrderLines
State
999992
107237
2173
2010-01-28 WILMINGTON
DE
19806 DB
15
1
1.
999993
20350
2173
2010-01-28 SWARTHMORE
PA
19081 DB
19.12
1.
999994
109529
2173
2010-01-28 SAN JOSE
CA
95118 VI
7.95
1
1
999995
109159
2173
2010-01-29 INDIANAPOLIS
IN
46214 VI
19.12
1
999996
113757
2173
2010-01-29 IOWA CITY
IA
52245 MC
19.12
1
1
999997
126445
2141
2010-01-29 STATEN ISLAND
NY
10308 AE
475
1
999998
131144
2173
2011-01-10 FARMINGTON
MI
48332 VI
22.5
1
1
999999
7040
2141
2011-01-10 JERICHO
NY
11753 AE
100
1
1000000
106192
2173
2011-01-10 ATLANTA
GA
30339 AE
34.95
1.
1
1000001
47149
2173
2010-01-28 HOLYOKE
MA
1040 DB
19.63
1
1000002
104162
2173
2010-01-28 CONYERS
GA
30012 DB
30
2
1000003
47355
2173
2010-01-28 PHILADELPHIA
PA
19119 DB
39.95
3
3
1000004
125694
2173
2010-01-29 VILLANOVA
PA
19085 AE
50
1.
1
1000005
104156
2173
2010-05-02 ARLINGTON
VA
22209 DB
24.95
2
2.
1000006
27600
2173
2010-01-30 BOGOTA
NJ
7603 DB
15
1000007
18531
2178
2011-07-07 FOREST HILLS
NY
11375 AE
17
1
1
1000008
108310
2141
2011-01-10 NEW YORK
NY
10016 AE
100
1.
1
1000009
53122
2141
2011-01-10 FAIRFAX
VA
22031 MC
10
1
1.
1000010
113686
2173
2010-01-28 FOREST HILLS
NY
11375 DB
195
1.
1000011
57966
2173
2010-01-28 ISLESFORD
МЕ
4646 DB
19.12
1
1
1000012
127017
2173
2010-01-28 LA PLUME
PA
18440 VI
19.12
1
1000013
88298
2141
2010-01-28 CLINTON
CT
6413 VI
15
1.
Transcribed Image Text:|Customer Campai OrderDate City ZipCod - Payme - TotalPrice - NumUnits NumOrderLines State 999992 107237 2173 2010-01-28 WILMINGTON DE 19806 DB 15 1 1. 999993 20350 2173 2010-01-28 SWARTHMORE PA 19081 DB 19.12 1. 999994 109529 2173 2010-01-28 SAN JOSE CA 95118 VI 7.95 1 1 999995 109159 2173 2010-01-29 INDIANAPOLIS IN 46214 VI 19.12 1 999996 113757 2173 2010-01-29 IOWA CITY IA 52245 MC 19.12 1 1 999997 126445 2141 2010-01-29 STATEN ISLAND NY 10308 AE 475 1 999998 131144 2173 2011-01-10 FARMINGTON MI 48332 VI 22.5 1 1 999999 7040 2141 2011-01-10 JERICHO NY 11753 AE 100 1 1000000 106192 2173 2011-01-10 ATLANTA GA 30339 AE 34.95 1. 1 1000001 47149 2173 2010-01-28 HOLYOKE MA 1040 DB 19.63 1 1000002 104162 2173 2010-01-28 CONYERS GA 30012 DB 30 2 1000003 47355 2173 2010-01-28 PHILADELPHIA PA 19119 DB 39.95 3 3 1000004 125694 2173 2010-01-29 VILLANOVA PA 19085 AE 50 1. 1 1000005 104156 2173 2010-05-02 ARLINGTON VA 22209 DB 24.95 2 2. 1000006 27600 2173 2010-01-30 BOGOTA NJ 7603 DB 15 1000007 18531 2178 2011-07-07 FOREST HILLS NY 11375 AE 17 1 1 1000008 108310 2141 2011-01-10 NEW YORK NY 10016 AE 100 1. 1 1000009 53122 2141 2011-01-10 FAIRFAX VA 22031 MC 10 1 1. 1000010 113686 2173 2010-01-28 FOREST HILLS NY 11375 DB 195 1. 1000011 57966 2173 2010-01-28 ISLESFORD МЕ 4646 DB 19.12 1 1 1000012 127017 2173 2010-01-28 LA PLUME PA 18440 VI 19.12 1 1000013 88298 2141 2010-01-28 CLINTON CT 6413 VI 15 1.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Query Syntax
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education