Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Replacing important missing data by row Expand / Collapse
Posted Thursday, July 25, 2013 11:09 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, January 23, 2015 6:01 PM
Points: 1, Visits: 22
This is my first post in many years so please forgive if this is the wrong forum. Been a DBA in a previous life and am now working with a client on a data feed and this issue has raised it's ugly head. The issue is we have a table that has SSNs in a data field, but not all rows have an SSN (the UI has the field as optional) so some users enter it and some don't, painful but true. What I want to do is where I have multiple rows and where the lastName, firstName and date of birth (DOB) are a match with another row and one of those rows have a valid SSN, I want to enter that valid SSN into that blank SSN field. In essence I would be entering the optional SSN in those rows where the user chose not to but for some reason had done it in the past or on a future entry.

ID lastName firstName DOB SSN other columns...
1 Doe John 1/1/1967 111-22-3333
2 Doe John 1/1/1967
3 Doe John 1/1/1967 111-22-3333

I am sure there is a elegant way to do this and while I have started poking at it, I thought I would hit some forums and look for help. Understood this might need some programming but if I can at least select the rows to start with the client can appreciate the counts and we can fix.
Appreciate any help

Steve Z
Post #1477635
Posted Thursday, July 25, 2013 11:24 AM

SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 12:50 PM
Points: 8,209, Visits: 17,763
I'm not sure you should do this as it might give you incorrect results if there are several people with same name and DOB (chances are low, but it could happen).
If you proceed with this, you could use this sample code to guide you.
ID int,
lastName varchar(20),
firstName varchar(20),
DOB date,
SSN varchar(20))
(1, 'Doe', 'John', '19670101', '111-22-3333'),
(2, 'Doe', 'John', '19670101', NULL),
(3, 'Doe', 'John', '19670101', '111-22-3333')

SSN = t2.SSN
FROM @Test t1
JOIN @Test t2 ON t1.lastName = t2.lastName
AND t1.firstName = t2.firstName
AND t1.DOB = t2.DOB

Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

How to post data/code on a forum to get the best help: Option 1 / Option 2
Post #1477645
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse