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
 Self join on a table help.

Author  Topic 

Bjcascone
Starting Member

37 Posts

Posted - 2010-07-14 : 16:15:12
I think that the solution to my problem is a self join, but i am not sure so i figured i would post here and hopefully someone can steer me in the right direction.

My problem: I have a view that look something like this:

SELECT
Case when A.ActualRecCnt <> B.RecordsSQL Then 'ERROR' else '' End as LoadErrorFlag
,B.[DataGroup]
,B.[SQLServer]
,B.[SQLDatabase]
,B.[TableName]
,A.[ExpectedCount]
,A.[ActualRecCnt]
,B.[RecordsWritten]
,B.[RecordsSQL]
,B.[ErrorCount]
,B.[LoadStartDate]
,B.[LoadEndDate]
,A.[VersionNumber]
,A.[SFileName]
,A.[FileDate]
,B.[FileName]
FROM [DBNAME].[dbo].[Tablename1] A
Join [DBNAME].[dbo].[TableName2] B
on replace(A.TblName,'_','') = Replace(replace(B.TableName,'_',''),'Load','')
and A.SFileName = B.SFileName
Join [DBName].[dbo].[TableName3] C
on C.TableName = replace(A.TblName,'_','')
Where FILEDate > '05/29/2010'

I want to add a column to this view that basically checks for duplication in one of the existing fields.

I have no idea as to where to start if anyone has any ideas for me i would appreciate the help.

- Brian

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-07-14 : 17:17:33
What do you mean by duplication?

DO you want to check to see if a column from A and a column from B are the same?

Maybe someting like:
CASE WHEN A.SFileName = B.SFileName THEN 1 ELSE 0 END AS IsSFileNameDuplicate
Go to Top of Page
   

- Advertisement -