Just Code‎ > ‎

SSMS - Regex to handle stuff copied from Excel to SSMS

posted Dec 14, 2011, 3:49 AM by Peter Henell
When you copy paste from Excel into SSMS the columns will be tab separated. If you want to perform some task for each for you can start from this little snippet. 
This snippet will find 4 columns and create tree rows for each row in the Excel document. The first cell in the Excel document will be present on each of the tree rows. This was used to unpivot data from an Excel document into several rows in a many-to-many table where the first column was meant to hold many of the other column (Car dealer owning many cars).


^({.*})\t({.*})\t({.*})\t({.*})$

('\1', '\2'), \n('\1','\3'),\n('\1','\4'),
Comments