Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Looking for suggestion/idea/help WITH T-SQL

$
0
0

Hi all,

The scenario I have is a person can have one or more charges on his/her case. 

One charge could be adjudicated as GUILTY and the other charge
is DROPPED.  If this is the scenario, I would like to assign GUILTY Adjudication to this case.

OR

One charge could be WITHHELD and the other charge is DROPPED. 
If this is the scenario, I would like to assign WITHHELD to this case.

Under Adjudication column, I would like to see GUILTY for case number 12345 and WITHHELD for case 98765

Sample data:

Case Number                Charge                       Charge                        Adjudication
                                                                    Disposition
==========           ======                    ===========          ============

12345                        DUI                             GUILTY
12345                        Driving w/o license       DROPPED


98765                        DUI                             WITHHELD  
98765                        Driving w/o license       DROPPED

Below is the query that returned the above sample Charge Disposition.  I am thinking of using CASE expression to determine Adjudication but not sure.

Thank you for everyone's help!

declare @Begindate datetime--
declare @Enddate datetime
set @begindate = '05/01/2014'
set @Enddate = '05/31/2014'


SELECT 
		(CASE 
			WHEN cc1.ProsecutorFinalAction IN ('L','O','R') AND 
				(cc1.ProsecutorFinalDecisionDate  >= @BeginDate) AND
				(cc1.ProsecutorFinalDecisionDate < DateAdd(d, 1, @EndDate))
						THEN pfa1.Description
			WHEN (cc1.CourtDecisionDate >= @BeginDate)AND 
				 (cc1.CourtDecisionDate < DateAdd(d, 1, @EndDate))
						THEN dbo.fnGetLookupDescription(cc1.CourtActionTaken,'CourtActionTaken')
			END)

				FROM tblCase c1 with(nolock)
					INNER JOIN tblCaseCharge cc1 with(nolock)
						ON c1.caseid = cc1.caseid
					LEFT OUTER JOIN tblProsecutorFinalAction pfa1 WITH(NOLOCK)
						ON cc1.ProsecutorFinalAction = pfa1.ProsecutorCode
				WHERE c1.CaseID = @CaseID


Viewing all articles
Browse latest Browse all 23857

Trending Articles