April 22, 2004 at 9:20 am
Hello All,
I getting SSN (hundreds of thousand of rows) from various sources,
so there are many caseses when SSN could be:
111-11-1111 --which is correct and
11111-1111 --which is Incorrect and
111111111 --which is Incorrect and
111-111111 --which is Incorrect and
111 11 1111 --which is Incorrect
At the end of the day I need to format SSN that way, so all SSN would have either only 9 charachters
like 111111111 or 11 charachters like 111-11-1111 ( which is even better!).
I use SQL 7.0., so I cannot really use UDF.
TIA
April 22, 2004 at 1:54 pm
For a format of format of nnn-nn-nnnn how about:
EXEC sp_addtype SSN, 'VARCHAR(11)', 'NOT NULL'
GO
CREATE TABLE ShowSSNUsage
(EmployeeID INT PRIMARY KEY,
EmployeeSSN SSN,
CONSTRAINT CheckSSN CHECK ( EmployeeSSN LIKE
'[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]' )
)
GO
Francis
April 23, 2004 at 2:34 am
That'll prevent future incorrect data.....Is the questioner not asking how to clean existing data?
select replace(replace(ssncol,'-',''),' ','') from ssntable
once it is cleaned....then it's just a case of parsing the result above into the required display formt.
April 23, 2004 at 7:48 am
Ok, this is simple. Create a Stored Proc for saving data into that Table. In that Proc, Clean the data!!! I ALWAYS create a Stored Proc for Saving and Deleting, and use Functions for retrieving complicated data. The fact that Stored Procs are used for "Business" Logic makes them the ideal location for complicated code...NOT IN YOUR CLIENT CODE!
Also, if you can, make your Client Code smarter. Forexample, use a MaskedEdit Box instead of a TextBox on the User Interfaces. That way you're absolutely sure that the data is formatted correctly. If you can't, fall back to Stored Procs for Saving again!
END
April 23, 2004 at 8:58 am
The above suggestions are good, but it is is an existing application, after you cleanup the data, make the cleanup a trigger. Regardless of how ever it comes in, it will be cleaned.
April 23, 2004 at 10:55 am
Ok, ericp37 has a point. If this is an existing app, you can create a Trigger very similar to what I suggested in the Stored proc, or I believe you can have the Trigger call a Stored Proc. Either way...but I suggest everything in the Trigger.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply