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,我无法发送所有查询,并且一对一发送需要很长时间,所以我需要一个动态查询,它得到一个与这些查询一样工作的唯一查询。也许使用案例?

4

1 回答 1

0

问题已通过 2 个查询和一个循环解决

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

在for循环之后,查询是它

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();它的全部!只有一个查询..

于 2012-05-11T14:46:05.530 回答