Connect your existing Source Control system to SSMS in 5 minutes
Getting started with SSIS - Part 1: Introduction to SSIS
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.
Loading

Ask in the public forum

Ask your questions in a public forum

My Blog Posts

SQL Server Monitoring
  • Assign identifier based on Match

    Hi ,

    I have problem in following scenario.

    I have one dataset that are matching people by firstname,lastname,DOB..i would like to give them uniqueID as  following example.

     

    Firstname

    lastname

    DOB

    NO_Match

    sudhir

    shah

    1/1/1960

    2

    sudhir

    shah

    1/1/1960

    2

    sandip

    kumar

    2/2/1920

    3

    farhan

    khan

    3/3/1965

    2

    sandip

    kumar

    2/2/1920

    3

    farhan

    khan

    3/3/1965

    2

    sandip

    kumar

    2/2/1920

    2

    output should be like following.

     

    Firstname

    lastname

    DOB

    NO_Match

    UID

    sudhir

    shah

    1/1/1960

    2

    1

    sudhir

    shah

    1/1/1960

    2

    1

    sandip

    kumar

    2/2/1920

    3

    2

    farhan

    khan

    3/3/1965

    2

    3

    sandip

    kumar

    2/2/1920

    3

    2

    farhan

    khan

    3/3/1965

    2

    3

    sandip

    kumar

    2/2/1920

    2

    2


    Can anyone  help out for that?

    Thanks in advance..

    Pavan
    734 · 0% · 21

6  Replies  

Subscribe to Notifications
  • Hi Jacob,

    i would like assign unique ID whom have  No_Match like 2,3 and so on... i have large dataset but this is just sample.

    so ID will be generate by query for assigning ID?

    is that thing you are asking?

     

    Thanks in advance...

    Pavan
    734 · 0% · 21
  • I asked this question because I saw that the UID column in your sample data is not unique. Records with year 1960 show "1" as UID. 1920 shows "2" and 1965 shows "3". What is the logic to be used to get these values?

    Jacob Sebastian
    1 · 100% · 16868
  • sorry for confusion..not UID but who ever people match by first name ,last name and DOB ,same id will be assign through dataset..

    i have used following logic to get NO_Match.

     

     

     

     

     

     

    WITH

     

     

    CTE AS (

    SELECT

     

    *,COUNT (*) OVER(PARTITION BY FirstName, LastName, DOB) AS cnt

    FROM db

     

     

    where Firstname is not null And lastname is not null and DateOFBirth is not null

    )

    SELECT

     

    *

    FROM cte WHERE cnt >1

     

    Thanks

    Pavan
    734 · 0% · 21
  • How about this?

    DECLARE @t TABLE (
        fname varchar(20), lname varchar(20), dob smalldatetime )
    INSERT INTO @t (fname, lname, dob)
    SELECT 'sudhir','shah','1/1/1960' UNION ALL
    SELECT 'sudhir','shah','1/1/1960' UNION ALL
    SELECT 'sandip','kumar','2/2/1920' UNION ALL
    SELECT 'farhan','khan','3/3/1965' UNION ALL
    SELECT 'sandip','kumar','2/2/1920' UNION ALL
    SELECT 'farhan','khan','3/3/1965' UNION ALL
    SELECT 'sandip','kumar','2/2/1920'
    
    SELECT 
        lname, 
        fname,
        dob,
        DENSE_RANK() OVER(ORDER BY fname, lname, dob) AS UID
    FROM @t
    /*
    lname  fname   dob         UID
    ------ ------- ----------- ---
    khan   farhan  1965-03-03  1
    khan   farhan  1965-03-03  1
    kumar  sandip  1920-02-02  2
    kumar  sandip  1920-02-02  2
    kumar  sandip  1920-02-02  2
    shah   sudhir  1960-01-01  3
    shah   sudhir  1960-01-01  3
    */
    
    Jacob Sebastian
    1 · 100% · 16868

Your Reply


Sign Up or Login to post an answer.

Managed Windows Shared Hosting by OrcsWeb

Copyright © Beyondrelational.com