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

Query two table into one result

$
0
0

Hi Everyone,

I'm trying to create a query that would query two table with some similar fields and a few unique one in one table.  I was trying to create it by using "Union" but that was fruitless.  Below is what I'm trying to accomplish.

I  wrote this but  it  doesn't work:

SELECT [Year], [Version], TransactionID, EmployeeID, FirstName, LastName, OfficeCode, CostCenterNo, UpdateBy, UpdateDateTime, [RowVersion]
FROM            BudgetHeader 
WHERE (CostCenterNo = '38101') AND ([Year]='2015') 
UNION
SELECT '2015' as  [Year], '1' as [Version],'' as TransactionID,EmployeeID, FirstName, LastName, OfficeCode, CostCenterNo, UpdateBy, UpdateDateTime,[RowVersion]
from Employee
WHERE (CostCenterNo = '38101')


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>