I have a text file in comma separated format. Each row has two columns and each column has integer values. Like
12334,23433
23234,45663
234422,324545
324543,23433
143233,23433
.....
The values in second columns are repeated. What I need to accomplish is that find all the values in first columns for which second column has same value and represent them in a row. Like for above data:
23433 12334,324543,143233
45663 23234
324545 234422
What I have done is following:
- Imported text file into SQL Server table using comma (,) as delimiter.
- Read text file from code per line.
- Split line on base of comma(,) and used second column value to send query to SQL Table.
- Store result in dictionary data structure where key is second column and concatenate all the results form first column value.
- After all processing, traverse dictionary and write it in a file.
This is definitely taking too much time. I have written code in C#. Any solution in T-SQL will work as well.
Any help to optimize it.