I have a mapping table that I need to query to generate my report. The
table structure is as below:

Mapping table
m_id m_table m_dept org dept id table
1 1 1 1 2 1 2
1 1 1 1 2 2 3
1 1 1 1 3 1 1

Corresponding to tables 1, 2 and 3 I have tables t1, t2 and t3 with the
following structure
table t1
org dept id desc
1 1 1 table 1 dept 1
1 2 2 table 1 dept 2

Quering the mapping table:
Select * from Mapping where m_id = 1 and m_table=1 and m_dept = 1
returns 3 rows as above.

Now I need to write a query that would use the above query result and
display records from tables t1, t2 or t3 based on above mapping where
the org, dept and id is equal to that in mapping table.
e.g.
above query should return something like this:

org dept id desc
1 2 1 table 2 dept 2
1 2 2 table 3 dept 2
1 3 1 table 1 dept 3

Re: need help writing query by sloan

sloan
Mon Sep 25 09:44:33 CDT 2006


You'll probably find better help at:
microsoft.public.sqlserver.programming







"absoft" <arpit.00@gmail.com> wrote in message
news:1159194650.710390.281910@k70g2000cwa.googlegroups.com...
> I have a mapping table that I need to query to generate my report. The
> table structure is as below:
>
> Mapping table
> m_id m_table m_dept org dept id table
> 1 1 1 1 2 1 2
> 1 1 1 1 2 2 3
> 1 1 1 1 3 1 1
>
> Corresponding to tables 1, 2 and 3 I have tables t1, t2 and t3 with the
> following structure
> table t1
> org dept id desc
> 1 1 1 table 1 dept 1
> 1 2 2 table 1 dept 2
>
> Quering the mapping table:
> Select * from Mapping where m_id = 1 and m_table=1 and m_dept = 1
> returns 3 rows as above.
>
> Now I need to write a query that would use the above query result and
> display records from tables t1, t2 or t3 based on above mapping where
> the org, dept and id is equal to that in mapping table.
> e.g.
> above query should return something like this:
>
> org dept id desc
> 1 2 1 table 2 dept 2
> 1 2 2 table 3 dept 2
> 1 3 1 table 1 dept 3
>



Re: need help writing query by absoft

absoft
Mon Sep 25 10:44:02 CDT 2006

ooooops .....ur right wrong forum
thanks for pointing out
cheers