Question : need to union a select statement

Hello,

I have the query below which works fine at present, however we're implementing an additional table - JBExpiredAdvert, which is where all records from JBAdvert go when they have been expired.

I need to somehow incorporate this change into the first inner join statement below as a union statement i guess (but haven't got a clue how to do it)

Any help please
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
Select
A.JBAPName Applicant,
AD.JBATitle JobTitle,
AD.JBAID AdvertID,
E.JBEName EmployeeName,
C.JBCLName ClientName,
CONVERT(CHAR(10),A.JBAPDate,103) AS ApplicationDate,
DATEPART(Month,A.JBAPDate) AS Month,  
DATEPART(Year,A.JBAPDate) AS Year,
A.JBAPRefer Referer
From dbo.JBApplication A 
inner join dbo.JBAdvert AD on AD.JBAID = A.JBAPAdvertID
inner join dbo.JBEmployee E on E.JBEID = A.JBAPEmployeeID
inner join dbo.JBClient C on C.JBCLID = A.JBAPClientID
Where JBAPSiteID = 30
Order by Year desc, Month desc

Answer : need to union a select statement

use this
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
Select
A.JBAPName Applicant,
AD.JBATitle JobTitle,
AD.JBAID AdvertID,
E.JBEName EmployeeName,
C.JBCLName ClientName,
CONVERT(CHAR(10),A.JBAPDate,103) AS ApplicationDate,
DATEPART(Month,A.JBAPDate) AS Month,  
DATEPART(Year,A.JBAPDate) AS Year,
A.JBAPRefer Referer
From dbo.JBApplication A 
inner join dbo.JBAdvert AD on AD.JBAID = A.JBAPAdvertID
inner join dbo.JBEmployee E on E.JBEID = A.JBAPEmployeeID
inner join dbo.JBClient C on C.JBCLID = A.JBAPClientID
Where JBAPSiteID = 30

union

Select
A.JBAPName Applicant,
AD.JBATitle JobTitle,
AD.JBAID AdvertID,
E.JBEName EmployeeName,
C.JBCLName ClientName,
CONVERT(CHAR(10),A.JBAPDate,103) AS ApplicationDate,
DATEPART(Month,A.JBAPDate) AS Month,  
DATEPART(Year,A.JBAPDate) AS Year,
A.JBAPRefer Referer
From dbo.JBApplication A 
inner join dbo.JBExpiredAdvert AD on AD.JBAID = A.JBAPAdvertID
inner join dbo.JBEmployee E on E.JBEID = A.JBAPEmployeeID
inner join dbo.JBClient C on C.JBCLID = A.JBAPClientID

Order by Year desc, Month desc
Random Solutions  
 
programming4us programming4us