I am importing sql into my Access database and am working on parsing the data into the correct tables and fields. Again I turn to you gurus to assist in a problem
One of the fields that is imported has comma separated values that need to be separated.there are anywhere from one to 10 possible values in the string.
PHO,Rosgen,NRCS,EMAP,T-DL,YSI-DL
I have figured out that if I make all of the values the same length (say 4 characters) I can get the 1st, last and 1st after the comma to parse but cannot seem to get the middle values extracted correctly.
SELECT Left([FieldForms],InStr([FieldForms],",")-1) AS DEQ_SampleTypeID
FROM tblSiteVisit
UNION ALL
SELECT Mid([FieldForms],InStr([FieldForms],",")+1,4) AS DEQ_SampleTypeID
FROM tblSiteVisit
UNION ALL
SELECT Mid([FieldForms], 11, 4) AS DEQ_SampleTypeID
FROM tblSiteVisit
UNION ALL
SELECT Mid([FieldForms], 16, 4) AS DEQ_SampleTypeID
FROM tblSiteVisit
UNION ALL
SELECT Mid([FieldForms], 21, 4) AS DEQ_SampleTypeID
FROM tblSiteVisit
UNION ALL
SELECT Mid([FieldForms],InStrRev([FieldForms],",")-4,4) AS DEQ_SampleTypeID
FROM tblSiteVisit
UNION ALL
SELECT Right([FieldForms],InStr([FieldForms],",")-1) AS DEQ_SampleTypeID
FROM tblSiteVisit
If I use the InStrRev or the Right Function I get repeats if there are fewer than the maximum also using the Mid functions results in empty rows.
Is there a way to parse out a string like this and only get results from the string
Split(FieldForms, ",")will give you a string array. Add a row to your destination table for each item in the array.