How to switch ID number to new values (but maintaining duplicates for new ones)

  • Hello!!!

    I need a database from an Insurance company, but they don't want to give it because it has a column with the ID number of each patient and their medical history.

    They will give it to me only if I can find a 'script' that allows them to switch that ID number, but I need to 'remember' same ID across all the dase...

    For example,

    If I have (in a column) the ID 12345 and you 54321, y must generate a new number for each one. It can be 1 for me and 2 for you; but each time it reads 12345 it has to change to 1 exclusively.

    In conlution, it has to identify each person with a new ID number.

    Thanks !!!

  • would doing something like selecting a newid() help?

    for example, have them do something like this:

    SELECT

    NEWID() AS RefID,

    OtherColumnsButNotTheRealID

    Into TableForExport

    From tblPatients

    --OR

    SELECT

    identity(int,1,) AS RefID,

    OtherColumnsButNotTheRealID

    Into TableForExport

    From tblPatients

    then have them send you the TableforExport, which would not have the sensitive column.

    they could do the same for patient names as well, if they needed to...just select a number instead of a patient name.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • or if you are lazy to list the column name do this.

    SELECT NEWID() AS [NewID], * INTO NewTable

    FROM ExistingTable;

    ALT_R TABLE NewTable DR_P COLUMN OldID

    *fill in the blank

  • lda17_04 (4/4/2013)


    Hello!!!

    I need a database from an Insurance company, but they don't want to give it because it has a column with the ID number of each patient and their medical history.

    They will give it to me only if I can find a 'script' that allows them to switch that ID number, but I need to 'remember' same ID across all the dase...

    For example,

    If I have (in a column) the ID 12345 and you 54321, y must generate a new number for each one. It can be 1 for me and 2 for you; but each time it reads 12345 it has to change to 1 exclusively.

    In conlution, it has to identify each person with a new ID number.

    Thanks !!!

    It's usually the responsibility of the supplier to obfuscate sensitive data - they should be posting the question on ssc, not you!

    Something like this:

    -- sample data

    DROP TABLE #SensitiveData;

    SELECT *

    INTO #SensitiveData

    FROM (SELECT PatientID = 1, SafeStuff = '1' UNION ALL SELECT 2, '2' UNION ALL SELECT 3, '3' UNION ALL SELECT 1, '1') d;

    -- generate the new keys

    DROP TABLE #ObfuscatedKeys;

    WITH DISTINCTPatientID AS (SELECT DISTINCT PatientID FROM #SensitiveData)

    SELECT SensitiveOldKey = PatientID, SafeNewKey = NEWID()

    INTO #ObfuscatedKeys

    FROM DISTINCTPatientID;

    -- switch keys for export

    SELECT o.SafeNewKey, s.SafeStuff

    FROM #SensitiveData s

    INNER JOIN #ObfuscatedKeys o ON o.SensitiveOldKey = s.PatientID;

    β€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Thank you very much for the assistance! πŸ˜€

    Yeah.... welll.. tell them that haha... Like always, if you want something you have to searched on your own.

    I will send them these suggestions, I hope they work fine.

    Thanks a lot !!!

    Any other idea please let me know.

  • πŸ™‚

Viewing 6 posts - 1 through 5 (of 5 total)

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