SQLTeam.com | Weblogs | Forums

T-sql 2012 compare two tables


#1

My goal is to compare data in Table1 in the database called test1 to
the data in Table1 in the database called test2. Both databases called test1
and test2 on the same database server called DBT. DBT database server is
SQL Server 2012. I want to find out what the differences are between the
2 tables. I want to find out exactly what the differences are.

The table is defined as:

Create Table1 (
username varchar(20) not null,
schoolnum varchar(03) not null,
MainRole char(01) not null
)

Here is example data:
username schoolnum mainRole
user1 040 Y
user2 040 N
user1 001 Y
user3 040 Y

Table1 does not have a key to the table. There can be
exact duplicate rows in this table.

Thus can you show me the t-sql 2012 so I can find where the
differnces between the 2 tables are?


#2

i put this under my where statement
FROM
#tmp_chargecapture T1- (TABLE1)
LEFT OUTER JOIN
DBO.CHARGECAPTURE T2 (TABLE COMPARE TABLE 1 TO)
ON T1.SessionID = T2.SessionID
WHERE NOT EXISTS
(SELECT SessionID
FROM #tmp_chargecapture T1
WHERE T1.SessionID = T2.SessionID)
ORDER BY T1.SESSIONID