dbTalk Databases Forums  

join 2 complex queries to 1

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss join 2 complex queries to 1 in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Beachvolleyballer
 
Posts: n/a

Default join 2 complex queries to 1 - 07-19-2004 , 09:14 AM






hi there

anyone had an idea to join following 2 queries to 1????


----- QUERY 1 ---------------------------------------------
SELECT TMS_CaseF_2.Name AS TCDomain_0,
TMS_CaseF_3.Name AS TCDomain_1,
TMS.CaseF.Name AS TCFolder_2,
TMS_CaseF_1.Name AS TCFolder_3,
TMS.TestCase.Name AS TCName_4,
TMS_TestCase_1.Name AS TCName_5,
TMS.LogFolder.Name AS PlannedLogFolder_6,
TMS.Log.Name AS PlannedLog_7,
TMS.CaseResult.RecordedCaseName AS TCRecordedName_8,
TMS.TestPlan.Name AS Plan_9
FROM
(
(
(
(
(
(
(
(
(
(TMS.Build INNER JOIN TMS.LogFolder ON TMS.Build.UID =
TMS.LogFolder.Build)
INNER JOIN TMS.Log ON TMS.LogFolder.UID = TMS.Log.LogFolder
)
INNER JOIN TMS.CaseResult ON TMS.Log.UID = TMS.CaseResult.Log
)
INNER JOIN TMS.TestCase ON TMS.CaseResult.TestCase =
TMS.TestCase.UID
)
LEFT JOIN TMS.CaseF ON TMS.TestCase.Parent = TMS.CaseF.UID)
LEFT JOIN TMS.TestCase AS TMS_TestCase_1 ON TMS.TestCase.Parent =
TMS_TestCase_1.UID
)
LEFT JOIN TMS.CaseF AS TMS_CaseF_1 ON TMS_TestCase_1.Parent =
TMS_CaseF_1.UID
)
LEFT JOIN TMS.CaseF AS TMS_CaseF_2 ON TMS_CaseF_1.Parent =
TMS_CaseF_2.UID
)
LEFT JOIN TMS.CaseF AS TMS_CaseF_3 ON TMS.CaseF.Parent =
TMS_CaseF_3.UID
)
INNER JOIN TMS.TestPlan ON TMS.TestCase.TestPlan = TMS.TestPlan.UID
)
WHERE (((TMS.LogFolder.Name) Like 'TR1%')
AND ((TMS.Build.Name)='Planning_VD10A'))
ORDER BY TMS.CaseF.Name,
TMS_CaseF_1.Name,
TMS.TestCase.Name,
TMS_TestCase_1.Name;
-------------------------------------------------------------




----- QUERY 2 ---------------------------------------------
SELECT TMS.CaseResult.RecordedCaseName
FROM ((TMS.Build INNER JOIN TMS.LogFolder ON TMS.Build.UID =
TMS.LogFolder.Build)
INNER JOIN TMS.Log ON TMS.LogFolder.UID = TMS.Log.LogFolder)
INNER JOIN TMS.CaseResult ON TMS.Log.UID = TMS.CaseResult.Log
WHERE (((TMS.LogFolder.Name) Like 'VD%')
AND ((TMS.Build.Name)='VD10A IT_APP'));

Reply With Quote
  #2  
Old   
Simon Hayes
 
Posts: n/a

Default Re: join 2 complex queries to 1 - 07-19-2004 , 12:38 PM







"Beachvolleyballer" <wl93 (AT) gmx (DOT) de> wrote

Quote:
hi there

anyone had an idea to join following 2 queries to 1????


----- QUERY 1 ---------------------------------------------
SELECT TMS_CaseF_2.Name AS TCDomain_0,
TMS_CaseF_3.Name AS TCDomain_1,
TMS.CaseF.Name AS TCFolder_2,
TMS_CaseF_1.Name AS TCFolder_3,
TMS.TestCase.Name AS TCName_4,
TMS_TestCase_1.Name AS TCName_5,
TMS.LogFolder.Name AS PlannedLogFolder_6,
TMS.Log.Name AS PlannedLog_7,
TMS.CaseResult.RecordedCaseName AS TCRecordedName_8,
TMS.TestPlan.Name AS Plan_9
FROM
(
(
(
(
(
(
(
(
(
(TMS.Build INNER JOIN TMS.LogFolder ON TMS.Build.UID =
TMS.LogFolder.Build)
INNER JOIN TMS.Log ON TMS.LogFolder.UID = TMS.Log.LogFolder
)
INNER JOIN TMS.CaseResult ON TMS.Log.UID = TMS.CaseResult.Log
)
INNER JOIN TMS.TestCase ON TMS.CaseResult.TestCase =
TMS.TestCase.UID
)
LEFT JOIN TMS.CaseF ON TMS.TestCase.Parent = TMS.CaseF.UID)
LEFT JOIN TMS.TestCase AS TMS_TestCase_1 ON TMS.TestCase.Parent =
TMS_TestCase_1.UID
)
LEFT JOIN TMS.CaseF AS TMS_CaseF_1 ON TMS_TestCase_1.Parent =
TMS_CaseF_1.UID
)
LEFT JOIN TMS.CaseF AS TMS_CaseF_2 ON TMS_CaseF_1.Parent =
TMS_CaseF_2.UID
)
LEFT JOIN TMS.CaseF AS TMS_CaseF_3 ON TMS.CaseF.Parent =
TMS_CaseF_3.UID
)
INNER JOIN TMS.TestPlan ON TMS.TestCase.TestPlan = TMS.TestPlan.UID
)
WHERE (((TMS.LogFolder.Name) Like 'TR1%')
AND ((TMS.Build.Name)='Planning_VD10A'))
ORDER BY TMS.CaseF.Name,
TMS_CaseF_1.Name,
TMS.TestCase.Name,
TMS_TestCase_1.Name;
-------------------------------------------------------------




----- QUERY 2 ---------------------------------------------
SELECT TMS.CaseResult.RecordedCaseName
FROM ((TMS.Build INNER JOIN TMS.LogFolder ON TMS.Build.UID =
TMS.LogFolder.Build)
INNER JOIN TMS.Log ON TMS.LogFolder.UID = TMS.Log.LogFolder)
INNER JOIN TMS.CaseResult ON TMS.Log.UID = TMS.CaseResult.Log
WHERE (((TMS.LogFolder.Name) Like 'VD%')
AND ((TMS.Build.Name)='VD10A IT_APP'));
I'm not entirely sure what you want to do, but you may be looking for either
a UNION or a derived table join:

select col1 as 'Column1'
from dbo.table1
union all
select col1
from dbo.table2

Note that UNION on its own will remove duplicate rows, but this takes extra
processing, so only use it if you know it's necessary, otherwise stick with
UNION ALL.

This is a derived table join:

select dt1.col1, dt1.col2, dt2.col2
from
(
select col1, col2
from dbo.table1
) dt1
join
(
select col1, col2
from dbo.table2
) dt2
on dt1.col1 = dt2.col1

If that's not helpful, perhaps you can clarify what you mean by 'joining'
two queries to one.

Simon




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.