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 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