|
meberg66219
Yak Posting Veteran
65 Posts |
Posted - 2010-09-23 : 16:24:46
|
| I did some research and found some good information on how to compare two tables in SQL. However, there are some errors in my code and I am not sure what is causing the query to error.Can anyone help?dbo.FaISIR11LastNameFirstNameAddressCityStateZipStudentEmailFatherLastNameFatherFirstNameMotherLastNameMotherFirstNameParentEmail********ORIGINATING TABLE**********dbo.FaFAFSA11LastNameFirstNameAddressCityStateZipStudentEmailFatherLastNameFatherFInitialMotherLastNameMotherFInitialParentEmail***********CODE TO COMPARE TABLES*********SELECT MIN(TableName) as TableName, ID, COL1, COL2, COL3 ...FROM( SELECT 'Table A' as TableName, A.ID, A.COL1, A.COL2, A.COL3, ... FROM A UNION ALL SELECT 'Table B' as TableName, B.ID, B.COL1, B.COl2, B.COL3, ... FROM B) tmpGROUP BY ID, COL1, COL2, COL3 ...HAVING COUNT(*) = 1ORDER BY ID**************MY CODE*********************SELECT MIN(dbo.FaISIR11) as dbo.FaISIR11, ID, dbo.FaISIR11.LastName, dbo.FaISIR11.FirstName, dbo.FaISIR11.Address, dbo.FaISIR11.City, dbo.FaISIR11.State, dbo.FaISIR11.StudentEmail, dbo.FaISIR11.FatherLastName, dbo.FaISIR11.FAtherFirstName, dbo.FaISIR11.MotherLastName, dbo.FaISIR11.MotherFirstName, dbo.FaISIR11.ParentemailFROM( SELECT 'dbo.FaISIR11' as dbo.FaISIR11, A.ID, A.dbo.FaISIR11.LastName, A.dbo.FaISIR11.FirstName, A.dbo.FaISIR11.Address, A.dbo.FaISIR11.City, A.dbo.FaISIR11.State, A.dbo.FaISIR11.StudentEmail, A.dbo.FaISIR11.FatherLastName, A.dbo.FaISIR11.FAtherFirstName, A.dbo.FaISIR11.MotherLastName, A.dbo.FaISIR11.MotherFirstName, A.dbo.FaISIR11.Parentemail FROM A UNION ALL SELECT 'dbo.FaFAFSA11' as dbo.FaFAFSA11, B.ID, B.dbo.FaFAFSA11.LastName, B.dbo.FaFAFSA11.FirstName, B.dbo.FaFAFSA11.Address, B.dbo.FaFAFSA11.City, B.dbo.FaFAFSA11.State, B.dbo.FaFAFSA11.Zip,B.dbo.FaFAFSA11.FatherLastname, B.dbo.FaFAFSA11,FatherFInitial B.dbo.FaFAFSA11.MotherLastName, B.dbo.FaFAFSA11.MotherFInitial, B.dbo.FaFAFSA11.ParentEmail FROM B) tmpGROUP BY ID, Last Name, First Name, Address, City, State, Zip, Student Email, Father Last Name, Father First Name, Mother Last Name, Mother First Name, Parent emailHAVING COUNT(*) = 1ORDER BY ID |
|