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 |
|
h4x0rmx
Starting Member
14 Posts |
Posted - 2008-09-18 : 13:33:52
|
I have a query that I use to create some reports between different day intervals (usually daily reports). It works great, but now I need the query to figure out by itself the current time and the current time minus 24 hrs. In Oracle I use the function SYSDATE. Is there a similar function on SQL Server?Here's an example query by the way (the original query is way to long and it might just confuse you)SELECT (( SUM(AStatistics.PriACD)+ SUM(AStatistics.PriCTI)+ SUM(AStatistics.OverACD)+ SUM(Atatistics.OverCTI)))FROM "CCenter1"."dbo"."AgStatistics" "AgStatistics" INNER JOIN "CCenter1"."dbo"."Ag" "Ag" ON "AgStatistics"."AgID"="Ag"."AgId" WHERE ("AgStatistics"."ReportDayDate">={ts '2008-09-11 00:00:00'} --I need the current timestamp - 24hrs AND "AgStatistics"."ReportDayDate"<{ts '2008-09-13 00:00:01'}) --I need the current timestamp AND "AgMap"."AgFolderIdentity"=9There are 10 kinds of people: those who understand binary and those who don't |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-18 : 13:38:12
|
quote: Originally posted by h4x0rmx I have a query that I use to create some reports between different day intervals (usually daily reports). It works great, but now I need the query to figure out by itself the current time and the current time minus 24 hrs. In Oracle I use the function SYSDATE. Is there a similar function on SQL Server?Here's an example query by the way (the original query is way to long and it might just confuse you)SELECT (( SUM(AStatistics.PriACD)+ SUM(AStatistics.PriCTI)+ SUM(AStatistics.OverACD)+ SUM(Atatistics.OverCTI)))FROM "CCenter1"."dbo"."AgStatistics" "AgStatistics" INNER JOIN "CCenter1"."dbo"."Ag" "Ag" ON "AgStatistics"."AgID"="Ag"."AgId" WHERE ("AgStatistics"."ReportDayDate">={ts '2008-09-11 00:00:00'} --I need the current timestamp - 24hrs AND "AgStatistics"."ReportDayDate"<{ts '2008-09-13 00:00:01'}) --I need the current timestamp AND "AgMap"."AgFolderIdentity"=9There are 10 kinds of people: those who understand binary and those who don't
for blue part useDATEADD(dd,-1,GETDATE())and for red part useGETDATE() |
 |
|
|
h4x0rmx
Starting Member
14 Posts |
Posted - 2008-09-18 : 13:52:15
|
quote: Originally posted by visakh16 for blue part useDATEADD(dd,-1,GETDATE())and for red part useGETDATE()
Will that use a "9/18/2008 9:49:31 AM" as a "2008-09-18 09:49:31"? I'm asking because I'm getting a NULL as a resultThere are 10 kinds of people: those who understand binary and those who don't |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-18 : 13:58:29
|
quote: Originally posted by h4x0rmx
quote: Originally posted by visakh16 for blue part useDATEADD(dd,-1,GETDATE())and for red part useGETDATE()
Will that use a "9/18/2008 9:49:31 AM" as a "2008-09-18 09:49:31"? I'm asking because I'm getting a NULL as a resultThere are 10 kinds of people: those who understand binary and those who don't
it will give back your current datetime value "2008-09-18 09:49:31" for "9/18/2008 9:49:31 AM"and "2008-09-18 21:49:31" for "9/18/2008 9:49:31 PM" |
 |
|
|
h4x0rmx
Starting Member
14 Posts |
Posted - 2008-09-18 : 14:16:58
|
quote: Originally posted by visakh16 it will give back your current datetime value "2008-09-18 09:49:31" for "9/18/2008 9:49:31 AM"and "2008-09-18 21:49:31" for "9/18/2008 9:49:31 PM"
Thanks! It does work, I don't know what I was doing wrong.I appreciate it!There are 10 kinds of people: those who understand binary and those who don't |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-18 : 14:26:59
|
quote: Originally posted by h4x0rmx
quote: Originally posted by visakh16 it will give back your current datetime value "2008-09-18 09:49:31" for "9/18/2008 9:49:31 AM"and "2008-09-18 21:49:31" for "9/18/2008 9:49:31 PM"
Thanks! It does work, I don't know what I was doing wrong.I appreciate it!There are 10 kinds of people: those who understand binary and those who don't
You're welcome |
 |
|
|
|
|
|