Solved

SQL "Today" filter help

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL replication over high latency link 10 61
SQL trigger 5 23
SQL Dump exec output to table 3 22
sql server query 18 42
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
I have a large data set and a SSIS package. How can I load this file in multi threading?
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
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.

830 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