Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Wobeca
Starting Member
12 Posts |
Posted - 2011-05-19 : 13:57:09
|
| Hi all,For school, I need to create a new Stored Procedure for my SQL Database.With this Stored procedure, I should be able to show a result of the total amount of money received of "today".The calculation for the total amount of money is no problem, but how do I get this to be calculated and shown for only "today"?My teacher indicated that I should create a View for this, and use this View in my new Stored Procedure...What I have (by example, fictitious tables) for the select statement:SELECT SUM(Amount) AS 'Income_Of_Today'FROM dbo.TblPaymentsNow what do I have to add to be sure the "Income of today" - column is only today's calculation?Sorry for the "noob" question...Thanks in advance!Greetz!Wobeca |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-05-19 : 14:18:36
|
| I hope I don't get kicked out of SQLTeam for answering homework/school project questions, but:You will need to add a WHERE clause to limit the query results just today's date.SQL's built in functions GETDATE(), CURRENT_TIMESTAMP etc. give you the current time - so if you use those, it would work for the current day.Those functions return date and time together. You will need to make sure that you get today's date rather than date and time. If you look up datetime and date data types, those should help you to do this relatively easily. |
 |
|
|
Wobeca
Starting Member
12 Posts |
Posted - 2011-05-19 : 16:10:55
|
| Thanks for your quick reply.I wasn't aware that school project questions weren't allowed?Anyway, thanks for the reply, and I will try to solve my problem with the help that you provided.Thanks! |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-05-19 : 16:14:48
|
| We won't do your homework for you. Offer advice and suggestions, sure. Give the solution, no.--Gail ShawSQL Server MVP |
 |
|
|
|
|
|
|
|