0

How can I Automatically generate sql insert scripts when data is available in some specific template in microsoft excel?Say for example i have four columns in the excel file as table_name and the others as column_1,column_2 and column_3 and their respective values. Now based on the values present in these columns the insert scripts has to be generated, like insert into table_name (column_1,column_2,column_3) values('v1','v2','v3'); . Suggest me the best way by which i can do this? Instead of microsoft excel other options are also fine.

1 Answer 1

1

For Excel to create insert statements:

"INSERT INTO table_name VALUES('"&A1&"','"&B1&"','"&C1&"')"

or

"insert into  product (product_id,name,date,price) values("&A1&",'" &B1& "','" &C1& "'," &D1& ");"
Sign up to request clarification or add additional context in comments.

4 Comments

the column name and table name are not always same and it is going to vary
are the table name and the column names always in the same columns/cells? if you don't wanna create the statements with a statement like above, you could also create i.e. a powershell which reads through the excel, creates the insert statements and executes them against the database
@EstebanP. can u please send me some reference links? where i can get to know how to proceed with the powershell thing.
@Karthik Link for reading through Excel: stackoverflow.com/questions/19211632/… Link for inserts through Powershell script: stackoverflow.com/questions/22974931/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.