Getting read of duplicates!

  • Hello people!! I thought I put your bright minds to the test! some puzzle came up at work, we have some duplicates on our database. Let me try to put it out clearly, we have two unlinked tables, one has info from our members and uses IGFAMemberID as a primary key, and the other has info from our users (not always members) based on a memberID criteria. For whatever reasons, for every IGFAMemberID in the members table we have two MemberID records in our users table. On our users table we have only one correct MemberId, the other one we can do without. I am trying to run a query or stored procedure that reads the two MemberIDs from the members table, then compares them to the users table and deletes the one who is not present on the user table. I sort of came with a stored procedure I think I got the logic correct but not the syntax, is this at all possible?

    CREATE PROC sp_FindDupes

    @p_IGFAMemberId numeric(18,0)

    AS

    DECLARE

    @v_MemberID numeric(18,0),

    @v_IGFAMemberID numeric(18,0)

    SELECT @v_MemberId = MemberID, @v_IGFAMemberID = IGFAMemberID

    FROM webuser.IGFAMembers

    WHERE IGFAMemberId = @p_IGFAMemberID

    IF @v_MemberID IN webuser.IGFAUsers

    PRINT @v_MemberID + ' is not a duplicate'

    ELSE IF @v_MemberID NOT IN webuser.IGFAUsers

    PRINT @v_MemberID + ' is a duplicate'

  • Welcome to SQLServerCentral.

    Please provide DDL and sample data

    Since this is your first post, you should be aware that you will often get responses such as this that state "Please provide DDL and sample data".

    Please read http://www.aspfaq.com/etiquette.asp?id=5006

    Here is the first paragraph:

    "Usually, narrative and a scribbled semblance of a table isn't enough to fully understand the structure and nature of your data, or at least not enough to solve your problem. So that we can spend more time actually working on your query (either solving an existing syntax or logic problem, or coming up with a way to get the output in your desired format), it helps if we can create the table on our system, and populate it with data, with minimal effort. If we have to waste time dreaming up fictitious data and guessing what you were describing in your word problem, we are likely going to give up. "

    Cheers

    SQL = Scarcely Qualifies as a Language

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply