|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
need help writing querytable 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 You'll probably find better help at:
microsoft.public.sqlserver.programming Show quote "absoft" <arpit***@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 > |
|||||||||||||||||||||||