0

私はこれらのようなクエリを持っています:

update table1 set quantity=(quantity)+3 where productsid=1
update table1 set quantity=(quantity)+4 where productsid=2
update table1 set quantity=(quantity)+5 where productsid=3
update table1 set quantity=(quantity)+6 where productsid=4
update table1 set quantity=(quantity)+1 where productsid=5
update table1 set quantity=(quantity)+3 where productsid=6
update table1 set quantity=(quantity)+2 where productsid=7

しかし、私はsqlceに取り組んでおり、すべてのクエリを送信できず、1つずつ送信するのに時間がかかるため、動的クエリが必要です。これらのクエリとして機能する唯一のクエリを取得します。多分ケースを使用しますか?

4

1 に答える 1

0

問題は2つのクエリと1つのループで解決されました

string query1 = " UPDATE table1  SET  quantity = CASE productsid  ";
string query_where = "END  WHERE productsid IN ";

のループの後、クエリはそれです

UPDATE table1  SET  quantity= CASE productsid  
When '1' Then quantity  - 2.0000000000 
When '2' Then quantity  - 2.0000000000 
When '3' Then quantity  - 1.0000000000 
When '4' Then quantity  - 1.0000000000 
When '5' Then quantity  - 1.0000000000 
When '6' Then quantity  - 5.0000000000 
When '7' Then quantity  - 1.0000000000 
When '8' Then quantity  - 1.0000000000 
When '9' Then quantity  - 1.0000000000 
END  WHERE productsid IN 
(  
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9'
) 

そして私は使うことができExecuteNonQuery();ましたそしてそのすべて!クエリは1つだけです。

于 2012-05-11T14:46:05.530 に答える