Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

comma delimited name column Expand / Collapse
Author
Message
Posted Thursday, May 22, 2008 9:39 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 17, 2013 2:02 PM
Points: 37, Visits: 114
I am not a DBA, but rather a .NET developer that has been thrust into working on an SQL database created using documentation and modeling from another database. The data is provided by the state of NC in a fixed length format. Getting the data into the database is no problem. The problem is that one of the searchable columns, the name column, is populated with the full name delimited by commas. My first thoughts are to create columns for the different name parts. The problem with that is the names sometimes do not follow the "last, first, middle, suffix" pattern. Some names in the column are of other nationalities that may consist of about five or six name parts. On top of that there are instances where there may be two or three commas before, after or in the middle of the name data.

Searching the data as it is was simplified by creating a full-text index and searching the data with the containstable and near predicates and functions. The issue comes in when I the searcher needs to search for different spellings, either by the end user or the person that entered the data. Example: "Keith or Keeth". The FORMSOF function doesn't seem to do the trick when searching the name column.

I have experimented with the Soundex function provided in SQL but that really doesn't seem to work on the comma delimited column data either. I get way too much useless results to deal with considering there are over 30 million rows of data to search.

Does anyone have any suggestions on the best approach for this problem?
Post #505280
Posted Friday, May 23, 2008 3:43 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, November 3, 2010 2:32 AM
Points: 1,249, Visits: 400
Without seeing actual examples of the data you are looking at this may be a bit difficult, but I have to ask the question, is your data not comma delimited by any chance.
If this is the case, then set the delimiter as comma when importing, and then have this imported to the seperate fields as you described that you would like to create.
The you may want to place full text indices on the columns to speed up your search functions.

Not that I know too much about full text indices, but if I had searches on strings, thats the first place I would investigate.
Post #505714
Posted Friday, May 23, 2008 7:01 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 17, 2013 2:02 PM
Points: 37, Visits: 114
No, the raw data comes as a fixed length file. The name column just contains commas. It could look like the following.

smith,john,thomas,jr
smith,john,thomas,sr
smith,john,thomas,,,
,,smith,john,thomas,
smith,john,,thomas,
smith,john,t,,,,,
,,,smith,,,john,thomas,
smith,john,thomas,AKA,John,thomas

No consistency at all and that is really frustrating.



Post #505807
Posted Tuesday, October 1, 2013 4:25 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, August 8, 2014 7:13 AM
Points: 15, Visits: 78
You can actually do like this just replace “,” with Single Quote & Comma & Single Quote will get you the answer. Along with that, we have to prepend “SELECT ” with a Single Quote and add a Single Quote at last.

the final code looks something like this

DECLARE @p NVARCHAR(MAX)
SELECT @P = 'AFGSDFGSDF,BSDF,CSDF,D'
DECLARE @STRSQL NVARCHAR(MAX)
SET @STRSQL = 'SELECT ''' + REPLACE(@P,',',''',''') + ''''
EXEC( @STRSQL)
Post #1500334
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse