0

In my Firebird database, I have a Table_Product which stores many individual numbered tables, for example:

   TBID PRODUCT  PRICE
    1       A      10
    1       B      20
    1       C      70
    ...

And I need to make an SQL INSERT to include a new one:

      TBNID PRODUCT  PRICE
        2       D      80
        2       F      40
        2       G      30

My new table data is in Excel file.

How could be an SQL Statement to accomplish it? How can I convert the excel table so I can plug the data into the SQL statement ?

INSERT INTO Table_Product (TBNID,PRODUCT,PRICE) values ... ?
5
  • 1
    It this a one shot operation or something you are going to do several times ? Commented Aug 4, 2017 at 2:47
  • Hi ! I will do it not frequently but at least twice a month Commented Aug 4, 2017 at 2:51
  • well in this case, you can save your excel as csv an use a command line tool like isql or fsql mujweb.cz/iprenosil/interbase/fsql.htm to insert Commented Aug 4, 2017 at 2:53
  • if you want to have something build into the excel file, you can do a quick vba macro which would read an area of a sheet, generate the insert, connect to the db and run inserts Commented Aug 4, 2017 at 2:55
  • humm, so I need to create a code to generate an insert for every row on my excel data ? so If I have 100 rows in my excel , I have to create 100 inserts , Is that correct ? Commented Aug 4, 2017 at 3:01

1 Answer 1

4

=" INSERT INTO Table_Product (TBNID, PRODUCT , PRICE) values ('"&H2&"','"&I2&"','"&J2&"') ;"

just change the Cell locations then drag down.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi, you mean , I need to do it in Excel first and then SQL ?
Yes, that will get the value based on cell locations and it will generate the script. If u have 100 records just drag down it will auto populate. Copy+paste it in ur DB then commit the script.
I got your idea. I didn't know this trick on spreadsheets. It worked. Thanks a lot !

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.