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
 Comparing data between two tables in same db

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2011-10-28 : 10:19:21
I'm having trouble with syntax errors in the following statement. It is intended to look at columns between two tables and find matching data. Both tables are in the same database. The first table is FSS_AFIS and the second is GCSOStatuteCodes. The intent is to have it find commonalities between the FSN column in the first table and the Statute# column in the second table. Any suggestions?:

USE GCSO_CONVERSION
SELECT MIN(CFG.dbo.FSS_AFIS) AS CTSCodes, FSN, FSDESC, ChargeNum
FROM(SELECT 'FSS_AFIS' AS FSS_Afis, A.FSN, A.FDESC, A.ChargeNum,
FROM DBO.GCSO_CONVERSION
UNION ALL
SELECT 'GCSOSTATUTECODES' AS GCSOStatuteCodes, B.STATUTE, B.[TEXT DESCRIP], B.ENTRY#,
FROM DBO.GCSO_CONVERSION
)TMP
GROUP BY FSN, FDESC,
HAVING COUNT(*) = 1
ORDER BY FSN

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2011-10-28 : 10:33:44
Disregard. I found a much more streamlined code to do the same.

thanks
Go to Top of Page
   

- Advertisement -