|
Question : SQL needs to ignore input mask
|
|
Greetings:
I have a sql query problem that despite all my efforts I am unable to solve. In the following query I am asking for items related to a specific social security number. The problem is if the table item does not have an input mask xxx-xx-xxxx, the query will not locate it. I need for the query to ignore the input mask and focus on the numeric i.e. 123456789 should return 123-45-6789 or 123-45-6789 should return 123456789
Query:
SELECT [Master Name Index].ID, [Master Name Index].Soc, [Master Name Index].[Last Name], [Master Name Index].[First Name], [Master Name Index].MI, [Master Name Index].MOB, [Master Name Index].DOB, [Master Name Index].YOB, [Master Name Index].Address, [Master Name Index].City, [Master Name Index].State, [Master Name Index].[Zip code], [Master Name Index].[Home phone], [Master Name Index].[Work phone], [Master Name Index].Race, [Master Name Index].Sex, [Master Name Index].Height, [Master Name Index].Weight, [Master Name Index].Hair, [Master Name Index].Eyes, [Master Name Index].Aliases, [Master Name Index].Date, [Master Name Index].Offense, [Master Name Index].Status, [Master Name Index].Officer, [Master Name Index].City, [Master Name Index].State, [Master Name Index].[Zip code], [Master Name Index].[Home phone], [Master Name Index].OLN, [Master Name Index].[DL State] FROM [Master Name Index] WHERE ((([Master Name Index].Soc)="123-45-6789") AND (([Master Name Index].[Last Name]) Is Not Null)) ORDER BY [Master Name Index].ID DESC;
|
|
Answer : SQL needs to ignore input mask
|
|
mickeyshelley1,
et and I have shown you two formula-based approaches; either one should work. Be advised that in either of our approaches, Jet will not be able to use any index you placed on Soc, so query performance will take a hit. You should run an update on your table to enforce consistency, either:
UPDATE [Master Name Index] SET Soc = Replace(Soc, "-", "")
or:
UPDATE [Master Name Index] SET Soc = Format(Soc, "999-99-9999")
Also, it is a bad, bad, bad idea to use spaces in table or field names.
Regards,
Patrick
|
|
|
|