title: How do you convert a CSV string into a table in SQL?
body: <p>Let's say you want to import a CSV file into a table in your SQL server, but you don't have the file, just a sting in CSV format. In our case, our design won't let us use one of the built-in file import functions (i.e. we don't actually have access to the file, just a string in CSV format; if you can access the file, see Underhill Julian's response below to save yourself the headache).</p>
  <p>After hours of Googling, I was desperately surprised to find that there isn't a built-in function to do this (at least in SQL Server 2017). Further, I couldn't find anyone that posted a function to accomplish this in a real-world scenario (outside of being passed a perfectly formatted string). The problem is that it isn't as easy as just splitting a string on commas and line breaks. What happens if you have a comma or line break <em>within</em> a column?</p>
  <p>After much, much head-banging-against-the-wall: Here you go. A truly dynamic procedure that will read in any CSV and spit out a dynamic table. See answer below.</p>