I want to add the column name to the beginning of each part of the string like on this mockup image.
One way i was thinking, is before i even use the the STRING_AGG, in a select statement select all columns and add the column name to row 1 of each column,
Then once I added the column name to row 1 of every column than i could use STRING_AGG. But not sure if that is a good approach.
And should probably check for NULL so that they always align....
slightwv (䄆 Netminder)
You have asked several related questions. What is your end goal for this data? You might look at a more commonly accepted data interchange method like JSON or XML instead of some hybrid CSV with parans, etc...
I have a csv file that was exported from a process.
But the csv files contains only pieces of data i need. It's not a straight data dump. In the csv it only has parts of the data.
For example the csv file might contain only the vendor last name and purchase date for an order.
Then I would use that vendor last name and purchase data info from the csv file and look up the order details from an existing sql server table and from the query result set, transfer those order details data into a different existing table.
For some thing like that would you recommend using JSON or XML?
slightwv (䄆 Netminder)
So how is writing SQL that generates a CSV string like "(a,b,c),(d,e,f)" going to help get data into some destination table?
Seems like pretty straight forward ETL. Load the columns you want from the original CSV into a staging table.
Then it might be as simple: Insert into destination table ( select ...);
Mark Wills
Sounds like there could be another new question happening pretty soon :)
Maybe with some sample data ? Edited of course so we can't see any data resembling "real life", more a symbolic representation of data..