tags:

views:

46

answers:

1

Trying to determine best way to code this requirement :

  • Need to insert rows to a SQL table having a multiple key index (PlantID,Year,Month).
  • Row may already exist could update or delete existing row.
  • Row contains around 150 fields that is dirived form other SQL tables.

Trying to determine simplest way to accomplish , I have thought would like to use SQLDataAdaptor, any ideas would be appreciated.

A: 

The SQL Query is easy:

Delete any existing rows first.

DELETE FROM table WHERE PlantID = "..." AND Year = "..." AND Month = "..."

And now insert the new one:

INSERT 
     INTO table (PlantID, Year, Month, other_col_1, ..., other_col_n)
     VALUES("...", "...", "...", "...", ..., "...")
opatut
Only if the input necessarilly includes all the other columns- which is not necessarilly the case from the question. If that data isn't part of your input, you'll lose it.
AllenG
BillTetrault wrote "Need to insert rows to a SQL table", not update...? So is all data known by the program? Maybe it is fetched in advance and put into an input form, where the user can change some values if desired. Any unchanged values will be still there...
opatut