?
Solved

SQL "Today" filter help

Posted on 2009-05-19
2
Medium Priority
?
251 Views
Last Modified: 2012-05-07
Hi

I am running the following query to find closed calls in our helpdesk system between two dates, I now need to produce the figure each day without changing the dates. I have created this as a view but was wondering how I can change this to just filter by todays date without having to manually change the date each day

SELECT    TOP 100 PERCENT dbo.RequestLog.RequestID, dbo.UDFVals.Val, dbo.RequestLog.Status, dbo.RequestLog.DateTime, dbo.Request.Summary,
                      dbo.CIID.Alpha1
FROM         dbo.RequestLog INNER JOIN
                      dbo.UDFVals ON dbo.RequestLog.RequestID = dbo.UDFVals.RQId INNER JOIN
                      dbo.Request ON dbo.RequestLog.RequestID = dbo.Request.ID AND dbo.UDFVals.RQId = dbo.Request.ID INNER JOIN
                      dbo.TIES ON dbo.Request.ID = dbo.TIES.RQID INNER JOIN
                      dbo.CIID ON dbo.TIES.CIID = dbo.CIID.ID
WHERE     (dbo.UDFVals.UDFId = '29') AND (dbo.RequestLog.DateTime >= CONVERT(DATETIME, '2009-04-27 00:00:00', 102)) AND
                      (dbo.RequestLog.DateTime < CONVERT(DATETIME, '2009-04-28 00:00:00', 102)) AND (dbo.RequestLog.Status = 'Closed') AND
                      (dbo.RequestLog.Cause = 'User')
ORDER BY dbo.RequestLog.RequestId
0
Comment
Question by:cntboys
[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
  • 2
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 24419829
null problemo:
SELECT    TOP 100 PERCENT dbo.RequestLog.RequestID, dbo.UDFVals.Val, dbo.RequestLog.Status, dbo.RequestLog.DateTime, dbo.Request.Summary, 
                      dbo.CIID.Alpha1
FROM         dbo.RequestLog INNER JOIN
                      dbo.UDFVals ON dbo.RequestLog.RequestID = dbo.UDFVals.RQId INNER JOIN
                      dbo.Request ON dbo.RequestLog.RequestID = dbo.Request.ID AND dbo.UDFVals.RQId = dbo.Request.ID INNER JOIN
                      dbo.TIES ON dbo.Request.ID = dbo.TIES.RQID INNER JOIN
                      dbo.CIID ON dbo.TIES.CIID = dbo.CIID.ID
WHERE     (dbo.UDFVals.UDFId = '29') 
AND (dbo.RequestLog.DateTime >= CONVERT(DATETIME, convert(varchar(10), getdate(), 120), 120)) 
AND (dbo.RequestLog.DateTime < dateadd(day, 1, CONVERT(DATETIME, convert(varchar(10), getdate(), 120), 120)))
AND (dbo.RequestLog.Status = 'Closed') 
AND (dbo.RequestLog.Cause = 'User')
ORDER BY dbo.RequestLog.RequestId

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24419845
btw, you should learn to use table aliases:
SELECT    TOP 100 PERCENT rl.RequestID, v.Val, rl.Status, rl.DateTime, r.Summary, c.Alpha1
FROM         dbo.RequestLog rl
INNER JOIN dbo.UDFVals v
 ON rl.RequestID = v.RQId 
INNER JOIN dbo.Request r 
  ON rl.RequestID = r.ID 
 AND v.RQId = r.ID 
INNER JOIN dbo.TIES t
  ON r.ID = t.RQID 
INNER JOIN dbo.CIID c
  ON t.CIID = c.ID
WHERE     (dbo.UDFVals.UDFId = '29') 
AND rl.DateTime >= CONVERT(DATETIME, convert(varchar(10), getdate(), 120), 120) 
AND rl.DateTime < dateadd(day, 1, CONVERT(DATETIME, convert(varchar(10), getdate(), 120), 120))
AND rl.Status = 'Closed' 
AND rl.Cause = 'User'
ORDER BY rl.RequestId

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

752 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