Solved

SQL "Today" filter help

Posted on 2009-05-19
2
248 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 500 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

738 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