Solved

SQL Query to locate all records in DB for today

Posted on 2007-12-06
3
180 Views
Last Modified: 2010-04-21
I am looking to create a SQL Query for my DotNetNuke site through SQL Report Server for all site log activity for today.  Here's what I've got so far:

SELECT     dnn_Portals.PortalName, dnn_SiteLog.DateTime, dnn_Users.Username, dnn_Users.FirstName, dnn_Users.LastName,
                      dnn_Tabs.TabName AS 'Resource Accessed'
FROM         dnn_Users INNER JOIN
                      dnn_SiteLog ON dnn_Users.UserID = dnn_SiteLog.UserId INNER JOIN
                      dnn_Portals ON dnn_SiteLog.PortalId = dnn_Portals.PortalID INNER JOIN
                      dnn_Tabs ON dnn_Portals.PortalID = dnn_Tabs.PortalID
WHERE     (dnn_Portals.PortalID = '0') AND (dnn_SiteLog.DateTime >= CONVERT(datetime, '12/6/2007 12:00:00 AM', 120)) AND
                      (dnn_SiteLog.DateTime < DATEADD(day, 1, CONVERT(datetime, '12/6/2007 11:59:59 PM', 120)))
GROUP BY dnn_Portals.PortalName, dnn_SiteLog.DateTime, dnn_Users.Username, dnn_Users.FirstName, dnn_Users.LastName, dnn_Tabs.TabName

As you can see, I've hard coded today's date, and this is working.  Now, I need to replace the hard coded date with some sort of today function but not sure what that is.

TIA for any help!
0
Comment
Question by:dstjohnjr
[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 25

Accepted Solution

by:
imitchie earned 500 total points
ID: 20424780
SELECT     dnn_Portals.PortalName, dnn_SiteLog.DateTime, dnn_Users.Username, dnn_Users.FirstName, dnn_Users.LastName,
                      dnn_Tabs.TabName AS 'Resource Accessed'
FROM         dnn_Users INNER JOIN
                      dnn_SiteLog ON dnn_Users.UserID = dnn_SiteLog.UserId INNER JOIN
                      dnn_Portals ON dnn_SiteLog.PortalId = dnn_Portals.PortalID INNER JOIN
                      dnn_Tabs ON dnn_Portals.PortalID = dnn_Tabs.PortalID
WHERE     (dnn_Portals.PortalID = '0') AND (dnn_SiteLog.DateTime >= CONVERT(DATETIME,CONVERT(Varchar,Getdate(),102)) ) AND
                      (dnn_SiteLog.DateTime < CONVERT(DATETIME,CONVERT(Varchar,Getdate()+1,102)) )
GROUP BY dnn_Portals.PortalName, dnn_SiteLog.DateTime, dnn_Users.Username, dnn_Users.FirstName, dnn_Users.LastName, dnn_Tabs.TabName
0
 

Expert Comment

by:xpert31415
ID: 20424817
SELECT Today=GETDATE()

returns

Today
---------------------------
2007-12-06 20:07:19.957

0
 

Author Closing Comment

by:dstjohnjr
ID: 31413305
That did it.  Thanks!
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

726 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