I have 4 rows in 'dataset' table in 'result' field and it is seperated by ampersand (&). I want to divide 'result' field into multiple fields based on field name. How do I do this in SSIS or SQL? Fieldname are higligtened. It would be nice it can be doable without .net script. If you notice, field names are jumbled.
Result (fieldname)
deptid=1 & firstname=din & lastname=kal & middlename=kum
firstname=raj & lastname=puli & middlename=kumar & deptid=2
firstname=pavan & lastname=gud & middlename=kumarrao
deptid=7 & firstname=sha & lastname=hank
Output
**deptid** **firstname** **lastname** **middlename**
1 din kal kum
2 raj puli kumar
pavan gud kumarrao
7 sha hank
CROSS APPLY
the table with some form of split string function. Use these results to create a Dynamic SQL command and execute. Persist these results to a new table andDROP
the old one. Storing data like that is not okay.Random SplitString:
A Test Case:
Problems Solved:
Now, with your nice, new table, you can perfom
ALTER ... COLUMN
statements to switch to some proper data types on those columns.should deliver what you want. It is using an intermediate XML object and xml processing to achieve the result. The intermediate column looks like
This solution is not absolutely fool proof, but if you are sure the format is stable and does not contain completely odd formated entries, it should work. Note: I need
contains
, as SQL Server does not seem to have atrim
function in XPath. This will fail in case a&
or=
are contained in the data for other purposes than separating field name from content or separating fields, i. e. if these characters would be contained in the names.