Inserting values into database from an excel

Hi,

I have a requirement where I have an excel sheet with the below values

 COL1        COL2       COL3
 Germany   URGENT   NORMAL

I want to cut the values of this excel in such a way that I get the values and pass it to an insert statement

update tbfin set value1=COL2,value2=col3 where table_name=col1;

can you please help with the logic for the same ?

Any attempts/ideas/thoughts from your side?

Anyway, here we go. I'm afraid I can't EXACTLY replicate your desired output as

  • it is NOT an insert (as requested) but an update statement
  • the case of line 1 field 2 & 3 don't match the output and can't be made up THAT easy.

On top, it's NOT easy (again) to extract from EXCEL immediately although there seems to exist a perl module therefor. I'll assume you created a <TAB> delimited text file instead.

If you're fine with an approximation, try

awk 'NR == 1 {print "update tbfin set value1=" $2 ",value2=" $3 " where table_name=" $1 ";"}' file
update tbfin set value1=COL2,value2=COL3 where table_name=COL1;

If you don't want the header info but the data, replace NR == 1 with NR > 1 or drop it entirely if you want ALL lines represented.

1 Like