Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL "Today" filter help

Posted on 2009-05-19
2
Medium Priority
?
253 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

Independent Software Vendors: 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

Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
What we learned in Webroot's webinar on multi-vector protection.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

597 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