Solved

SQL "Today" filter help

Posted on 2009-05-19
2
241 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
  • 2
2 Comments
 
LVL 142

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 142

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now