-1

I have a google Sheets that looks like this :

ID | City | Capital | Country
-------------------------------
5  | Paris | Yes | France
8  | Madrid| Yes | Spain 

I would like to find a way to generate this kind of code for each line

 update database set city='Paris' and Country='France' where id=5
IF @@ROWCOUNT=0
   insert into database(city,country) values('Paris','France');

I would like to generate a big file that concatenate all the SQL queries like the one above (one for each row), so I can just update my database with this.

player0
  • 124,011
  • 12
  • 67
  • 124
  • You've almost done it already. Just put the sql in a column on the sheet and use concatenation to fill in the variable data from the relative cells. – topsail Nov 22 '22 at 23:32
  • share a copy / sample of your sheet with an example of the desired output – player0 Nov 22 '22 at 23:58

1 Answers1

0

try:

="update database set city='"&B2&"' and Country='"&D2&"' where id="&A2&"
IF @@ROWCOUNT=0
   insert into database(city,country) values('"&B2&"','"&D2&"');"
player0
  • 124,011
  • 12
  • 67
  • 124