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 |
haibec
Yak Posting Veteran
54 Posts |
Posted - 2008-01-17 : 11:52:32
|
Hi all!I have a form search result(by ASP) all custumer buy product in a day. Result include ID,Name,ProductId,Price,Time. Now, i want my page print total "Price" of all customer buy product in time. Please help me |
|
georgev
Posting Yak Master
122 Posts |
Posted - 2008-02-17 : 11:19:10
|
Simplest answer is to open a second recorset with a query that returns just that![CODE]SELET Sum(price)FROM yourTableWHERE DateAdd(dd, DateDiff(dd, 0, date_purchased), 0) = DateAdd(dd, DateDiff(dd, 0, GetDate()), 0)[/CODE] George<3Engaged! |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-02-17 : 16:27:08
|
Simpler...SELET Sum(price)FROM yourTableWHERE DateDiff(dd, 0, date_purchased) = DateDiff(dd, 0, GetDate())But if you are interested in using your existing indexes, usedeclare @anyday datetimeset @anyday = '20080213'SELECT Sum(price)FROM yourTableWHERE date_purchased >= dateadd(day, DateDiff(day, '19000101', @anyday), '19000101')and date_purchased < dateadd(day, DateDiff(day, '18991231', @anyday), '19000101') E 12°55'05.25"N 56°04'39.16" |
|
|
|
|
|
|
|