Using sql update with multiple where conditions

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by