Excel Formula to create SQL Script for a Values Table

  • Comments posted to this topic are about the item Excel Formula to create SQL Script for a Values Table

  • I just noticed that you need the table to start in column 1 for this to work properly. Although here is a version that works if the table starts at any column (it checks if the column is the min column in the table to add the first values bracket and checks if it is the last column (min column number + column count minus 1) to see if it needs the bracket at the end of the value group.

    ="SELECT "&CHAR(10)&" ["&TEXTJOIN("],[",FALSE,Table1[#Headers])&"]"&"

    FROM

    (VALUES "&TEXTJOIN(",",FALSE,IF(COLUMN(Table1)=MIN(COLUMN(Table1)),CHAR(10)&"('","'")&SUBSTITUTE(Table1,"'","''")&IF(COLUMN(Table1)=(COLUMNS(Table1)+MIN(COLUMN(Table1))-1),"')","'"))&") t1 (["&TEXTJOIN("],[",FALSE,Table1[#Headers])&"])"

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply