Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Join 2 temporary tables

Author  Topic 

vijay1234
Starting Member

48 Posts

Posted - 2014-07-01 : 00:49:24
*****

stepson
Aged Yak Warrior

545 Posts

Posted - 2014-07-01 : 02:09:07
[code]
;with TempComp
AS
(SELECT 'BHPB' AS [VMRCompanyName], 20 AS [No of Meetings],'2014-06-30' AS [Date of Meeting] UNION ALL
SELECT 'BHPBPVT',5,'2014-06-30' UNION ALL
SELECT 'GLW',2,'2014-06-30' UNION ALL
SELECT 'HP',46,'2014-06-30')

,TempComp1
AS
(SELECT 'BHPB' AS [VMRCompanyName],11 AS [No of Meetings],'2014-06-30' AS [Date of Meeting] UNION ALL
SELECT 'BHPBPVT',2,'2014-06-30' UNION ALL
SELECT 'HP',5,'2014-06-30' UNION ALL
SELECT 'KPMG',20,'2014-06-30')

SELECT
ISNULL(T.VMRCompanyName,T1.VMRCompanyName) AS [VMRCompanyName]
,T.[No of Meetings] AS [NoofMeetings(#TempComp)]
,T1.[No of Meetings] AS [NoofMeetings(#TempComp1)]
,ISNULL(T.[Date of Meeting],T1.[Date of Meeting]) AS [Date of Meeting]
FROM
TempComp AS T
FULL JOIN TempComp1 AS T1
ON T.VMRCompanyName=T1.[VMRCompanyName]
AND T.[Date of Meeting]=T1.[Date of Meeting]
[/code]

For BHPB,06-30-2014 , you have 10 , 12
This query ,for BHPB,06-30-2014 , return 20 NoofMeetings(#TempComp),11 NoofMeetings(#TempComp1)






sabinWeb MCP
Go to Top of Page
   

- Advertisement -