Link to home
Start Free TrialLog in
Avatar of RIAS
RIASFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Combine two sql queries

Hi,
I have 2 queries ,any help on how to combine them will be appreciated
Specification for the query :

Where  [Status] at %Input_Date%  = “Active” or “Preserved Pensioner” or “Pensioner” or  “Widow(er)”  or “Child” ---is it the latest entry
OR where  [Status] at %Input_Date%  = “No Liability”
and  [Dateleft], [Dbdate], [Pdpencomm] or [Topaid]  later than (%Input_Date% less 1 Year)

Query1:

Select *  From Personal_Details where PERSONAL_DETAILS.CURRSTATUS = 'PRESERVED PENSIONER' and DateJS > datejc

Query2:

 select * from Personal_Details a inner join DEATH_BENEFIT b on a.REFNO=b.REFNO inner join PENSIONER_DETAIL c on c.REFNO=a.REFNO inner join TRANSFER_OUT_HISTORY d on d.REFNO=a.REFNO where (a.CURRStatus in ('Active','PreservedPensioner','Pensioner','Widow','Child','No Liability')) and (a.Dateleft > dateadd(y,17/06/2011,-1)) or  b.dbdate > dateadd(y,17/06/2011,-1)   or c.pdpencomm  > dateadd(y,17/06/2011,-1) or d.topaid > dateadd(y,17/06/2011,-1)
Avatar of lisa_mc
lisa_mc
Flag of United Kingdom of Great Britain and Northern Ireland image

Try this I think its what you need


select * from Personal_Details a
inner join DEATH_BENEFIT b on
a.REFNO=b.REFNO 

inner join PENSIONER_DETAIL c on
c.REFNO=a.REFNO 

inner join TRANSFER_OUT_HISTORY d on 
d.REFNO=a.REFNO 

where (a.CURRStatus in ('Active','PreservedPensioner','Pensioner','Widow','Child')
or (a.CURRStatus = 'No Liability'
and ((a.Dateleft > dateadd(y,17/06/2011,-1)) or  (b.dbdate > dateadd(y,17/06/2011,-1))   
or (c.pdpencomm  > dateadd(y,17/06/2011,-1)) or (d.topaid > dateadd(y,17/06/2011,-1)))  )

Open in new window

Avatar of RIAS

ASKER

Hi,
Got error :
Msg 102, Level 15, State 1, Line 14
Incorrect syntax near ')'.


Thanks
ASKER CERTIFIED SOLUTION
Avatar of lisa_mc
lisa_mc
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RIAS

ASKER

Cheers mate
you are very welcome glad I could help
happy coding :-)