Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


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


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

Author
Message
lda17_04
lda17_04
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 4
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 !!!
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14955 Visits: 38948
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!

haiao2000
haiao2000
SSC-Enthusiastic
SSC-Enthusiastic (164 reputation)SSC-Enthusiastic (164 reputation)SSC-Enthusiastic (164 reputation)SSC-Enthusiastic (164 reputation)SSC-Enthusiastic (164 reputation)SSC-Enthusiastic (164 reputation)SSC-Enthusiastic (164 reputation)SSC-Enthusiastic (164 reputation)

Group: General Forum Members
Points: 164 Visits: 438
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
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)

Group: General Forum Members
Points: 8957 Visits: 19016
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
Exploring Recursive CTEs by Example Dwain Camps
lda17_04
lda17_04
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 4
Thank you very much for the assistance! :-D

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.
lda17_04
lda17_04
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 4
:-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search