Using sql update with multiple where conditions

3 ビュー (過去 30 日間)
Gerald Blumberg
Gerald Blumberg 2016 年 8 月 2 日
回答済み: Gerald Blumberg 2016 年 8 月 3 日
Hello,
I am trying to use the update function to update my sql database. Even though I went to the documentation I still have trouble to update a table of the following structure:
Date........ID........Value1........ Value2
--------------------------------------
1.1............1...........5................7
1.1............2...........3................8
...
2.1............1...........9................12
2.1............2...........1............... 333
As you will recognize, "ID" as well as "Date" values occure more than ones and aren't unique. Only the combination of both is unique. Thats why I need multiple whereclause conditions!
Imagine I want to update the column "Value2" in the first 2 rows. How would I do that? I found some solutions using set and case but i want to update some thousends of data thats why hard coding the combination would be pretty uncool...
So far I have a valid connection "conn" and a cell ("cell2insert") which obtains a new value in each row; i.e. cell2insert = {1;2}; Additionally, I have a cell "whereclause" obtaining strings: whereclause = {'where Date = 1.1. and ID = 1' ; 'where Date = 1.1. and ID = 2'};
Using this, I try to apply "update": update(conn, aim , {'Value2'} , cell2insert , whereclause); (where aim is my database table)
I tryed to use a table instead of cell2insert but failed anyway...
Thanks in advance and regards, Gerald

採用された回答

Gerald Blumberg
Gerald Blumberg 2016 年 8 月 3 日
found the misktake! the whereclause must be: whereclause = {'where Date = ''1.1.'' and ID = ''1''' ; 'where Date = ''1.1.'' and ID = ''2'''};

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by