Solved

Sub Requirements in SQL Query

Posted on 2009-05-14
2
128 Views
Last Modified: 2012-05-07
Here is what I have so far, however there are a few mods I need and am not sure of.  Instead of WHERE     (Status <> 'Closed') AND ([Date Opened] <= DATEADD(dd, - 8, DATEDIFF(dd, 0, GETDATE()))) I need this to check the Priority and then be able to set the dd, -8 to different amounts based upon Priority level, and I need to set a couple different requirements at once. For instance if it is priority 2 then I want to set the dd, -2 while priority 4 is dd, -8

SELECT     *

FROM         (SELECT     Incident_ID AS [Ticket Number], CONVERT(datetime, DateClosed / 86402.027 + 25567) AS [Date Closed], 

                                              AssignedGroup AS [Assigned Group], AssignedTechnician AS [Assigned Technician], 

                                              CASE Priority WHEN 4 THEN 'Low' WHEN 3 THEN 'Medium' WHEN 2 THEN 'High' END AS Priority, 

                                              CASE Status WHEN 3 THEN 'Closed' WHEN 8 THEN 'Drill Status' WHEN 4 THEN 'Hold' WHEN 1 THEN 'Assigned' WHEN 0 THEN 'New' WHEN

                                               9 THEN 'Project' END AS Status, CONVERT(datetime, Date_Opened / 86402.027 + 25567) AS [Date Opened], 

                                              CASE COMPLEXITY WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' END AS [Suspense Missed]

                       FROM          dbo.TTS_Main) derived

WHERE     (Status <> 'Closed') AND ([Date Opened] <= DATEADD(dd, - 8, DATEDIFF(dd, 0, GETDATE()))) AND (Status <> 'Project')

Open in new window

0
Comment
Question by:141ANG
2 Comments
 
LVL 25

Accepted Solution

by:
reb73 earned 500 total points
Comment Utility
Like this ?
SELECT     *

FROM         (SELECT     Incident_ID AS [Ticket Number], CONVERT(datetime, DateClosed / 86402.027 + 25567) AS [Date Closed], 

                                              AssignedGroup AS [Assigned Group], AssignedTechnician AS [Assigned Technician], 

                                              CASE Priority WHEN 4 THEN 'Low' WHEN 3 THEN 'Medium' WHEN 2 THEN 'High' END AS Priority, 

                                              CASE Status WHEN 3 THEN 'Closed' WHEN 8 THEN 'Drill Status' WHEN 4 THEN 'Hold' WHEN 1 THEN 'Assigned' WHEN 0 THEN 'New' WHEN

                                               9 THEN 'Project' END AS Status, CONVERT(datetime, Date_Opened / 86402.027 + 25567) AS [Date Opened], 

                                              CASE COMPLEXITY WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' END AS [Suspense Missed]

                       FROM          dbo.TTS_Main) derived

WHERE   (Status <> 'Closed')

AND	(Status <> 'Project')

AND 	([Date Opened] <= CASE	WHEN Priority = 2 THEN DATEADD(dd, - 2, DATEDIFF(dd, 0, GETDATE()))

				WHEN Priority = 3 THEN DATEADD(dd, - 5, DATEDIFF(dd, 0, GETDATE()))

			  	WHEN Priority = 3 THEN DATEADD(dd, - 8, DATEDIFF(dd, 0, GETDATE()))

			  END

	)

Open in new window

0
 
LVL 1

Author Closing Comment

by:141ANG
Comment Utility
This worked great, thankyou
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sql help 5 48
MySQL Insert Combined IDs from 2 Unrelated tables 9 42
how to remove non-duplicated row 5 25
SQL query 4 25
In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

9 Experts available now in Live!

Get 1:1 Help Now