Convert data in excel to .sql

Hi,
My actual issue is to fetch and pass a dynamic value in query.(Please excuse for the lengthy post)

For my requirement, I need to run 3 queries to approve a request in backend -

  1. INSERT INTO a tableA – insert the intitation data/record to the tableA
  2. SELECT FROM the tableA – select the latest inserted record from the tableA and fetch the value of Field1 (the value of Field1 changes with every run of 1st query)
  3. INSERT INTO tableB– pass the value of Field1 fetched from previous select query and use it to insert approval data

The issue here lies between the 2nd and 3rd query. I have explained in detail the steps I have followed so far -

Inside an Excel loop -
i)create datatable
ii)execute DBquery (2nd query - SELECT FROM tableA)
iii)get data (fetch value of Field1)

at this stage, I have split the 3rd query in two parts like below -
part1 = INSERT INTO tableB VALUES ("
part2 = ",‘xxxx’, ‘xxxx’, ‘xxxx’)

iv) Assign 3rd query = part1 + “Field1” + part2
v) Write 3rd query to excel

Till here everything is going as expected. Now I have to convert the contents of this excel i.e., 3rd query to .sql and execute it. But the ‘convert’ option in file operations doesn’t support .sql file type, hence i’m not able to proceed further.

Is there a way I can convert this to .sql? or is there an alternative to this entire process of passing dynamic values altogether? Please advice.

Hi,

Try renaming the fille option

Regards,
Amit Anand

Hi,
This didnt work for me. I tried option ‘Rename’ in file operations to rename excel as .sql , but it resulted in creating a file as ‘query3.sql.xlsx’. The SQL management studio failed to open this file type.
Also renaming or converting excel file with multiple sheets will be a problem.

Hi,

Ok. I guess it renames the file and does not change extension.

You can extract the text from excel using AE tool and then write a microbot to write the content in a .sql file

Regards,
Amit Anand