General discussion

Locked

T-SQL querying multiple tables based on certain conditions

By lavan_baloo ·
Hi,

I have a situation where i need to query multiple tables (12 tables) within a database for records containing values that are listed in another table and also based on a certain conidition.

Specifically, i have a EMP table with a list of employee names, date of joining, office address etc. I have 12 other tables that contain detailed information for all employees split into 12 monthly tables, based on date of joining.

I need a query to list all information in these 12 tables for all employees that are listed in table EMP for employees that joined before certain date (the date field and EMP number is common to the EMP field and all the 12 tables).

Can you help me?
thnak you in advance!

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Ugly method

by Tony Hopkinson In reply to T-SQL querying multiple t ...

select * from (

select * From emp,empJan
Where emp.empno = empjan.empno
union
select * From emp,empFeb
Where emp.empno = empFeb.empno
union
....
union
select * From emp,empDec
Where emp.empno = empDec.empno
) allemps
where date_joined < ?????

There are some less messy but more complex solutions.

Not used them myself, but look up user defined functions and table variables.

Back to Software Forum
1 total post (Page 1 of 1)  

Related Forums