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
 General SQL Server Forums
 New to SQL Server Programming
 I need help on how to compare two TEMP tables?

Author  Topic 

osirisa
Constraint Violating Yak Guru

289 Posts

Posted - 2007-11-02 : 10:29:08
I need help on how to compare two temp tables. I have to compare two temp tables from two diferent server. Here is what I have done so far...

   CREATE  PROC dbo.swn_sp 

AS
/********************************************************************
* Program Name :
*
*
*********************************************************************
*
* Modification History:
*********************************************************************

--*************************************************************
--SET SQL STMT BASED ON SQL TYPE PASSED IN
--*************************************************************/

/* Create a Temp Table */

Create Table #TP_DGC(
station_nbr char (20),
station_name varchar (40),
group_code char (12),
beg_eff_date_DGC datetime,
end_eff_date_DGC datetime)


--------------Selection Gathering Table-------------------


DECLARE @groupcode char (12),
@stationnumber char(20),
@stationame varchar(40),
@begdateG datetime,
@endeffdateG datetime,
@Records int,
@record_found_flag char(1),
@current_date datetime


SELECT Distinct a.station_nbr, c.station_name, a.group_code,
a.beg_eff_date As beg_eff_date_DGC, a.end_eff_date As End_eff_date_DGC
from TIES_Gathering.dbo.station_group a
Inner Join TIES_Gathering.dbo.station c on a.station_nbr = c.station_nbr
Inner Join TIES_Gathering.dbo.station_type d on a.station_nbr = d.station_nbr
Inner Join TIES_Gathering.dbo.group_detail e on a.group_code = e.group_code
Where ((e.group_type = 'NPN')or(e.group_type = 'WTF')or(e.group_type = 'NTF'))and
((d.type_code = 'WHM')or (d.type_code = 'CRP')) and (a.pipeline_code = '100000')
Order by a.station_nbr, a.group_code


INSERT INTO #TP_DGC(station_nbr,station_name,group_code,beg_eff_date_DGC,end_eff_date_DGC)
values (@stationnumber, @stationame,@groupcode,@begdateG,@endeffdateG)


--------------Selection Marketing Table-------------------


Create Table #TP_SES(
station_nbr char (20),
station_name varchar (40),
group_code char (12),
beg_eff_date_SES datetime,
end_eff_date_SES datetime)



DECLARE @groupcode_M char (12),
@stationnumber_M char(20),
@stationame_M varchar(40),
@begdateM datetime,
@endeffdateM datetime,
@Records_M int,
@record_found_flag_M char(1)


Select Distinct a.station_nbr,b.station_name,a.group_code, a.beg_eff_date As beg_eff_date_SES, a.end_eff_date As End_eff_date_SES
From TIES_Marketing.dbo.station_group a
Inner Join TIES_Marketing.dbo.station b on a.station_nbr = b.station_nbr
Inner Join TIES_Marketing.dbo.station_type c on a.station_nbr = c.station_nbr
Inner Join TIES_Marketing.dbo.group_detail e on a.group_code = e.group_code
Where ((c.type_code = 'WHM')or (c.type_code = 'CRP')) and (a.pipeline_code = '100001')
Order by a.station_nbr, a.group_code



INSERT INTO #TP_SES(station_nbr,station_name,group_code,beg_eff_date_SES,end_eff_date_SES)
values (@stationnumber, @stationame,@groupcode,@begdateM,@endeffdateM)




---------------compare both tables--------------------
Begin

Select #TP_SES.station_nbr, #TP_SES.station_name, #TP_SES.station_group,
#TP_DGC.beg_eff_date As beg_eff_date_DGC, #TP_DGC.end_eff_date As End_eff_date_DGC,
#TP_SES.beg_eff_date As beg_eff_date_SES,#TP_SES.end_eff_date As End_eff_date_SES
from #TP_SES left outer join #TP_DGC on station_nbr=station_nb
end


----- drop temporary tables---

drop table #TP_DGC
drop table #TP_SES

go



Thanks in advance for the Help!!!!!

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-11-02 : 10:33:50
Great! Thanks for letting us know.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-11-02 : 10:49:31
quote:
Originally posted by jsmith8858

Great! Thanks for letting us know.

- Jeff
http://weblogs.sqlteam.com/JeffS




you crack me up



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

osirisa
Constraint Violating Yak Guru

289 Posts

Posted - 2007-11-02 : 14:44:35
Posted - 11/02/2007 : 10:49:31
--------------------------------------------------------------------------------

quote:
--------------------------------------------------------------------------------
Originally posted by jsmith8858

Great! Thanks for letting us know.

- Jeff
http://weblogs.sqlteam.com/JeffS


--------------------------------------------------------------------------------



you crack me up


Ditto----- You crack me uppppppppppppppp!!!!
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-11-02 : 14:48:14
osirisa -- do you understand that you did not ask a question? And that you did not provide any information whatsoever about what problem you are having?

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-11-02 : 15:08:02
Patricia,

How's Houston these days?

They still have Good and Company seafood?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -