我有这样的疑问:
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我无法发送所有查询,并且一对一发送 花费很多时间,所以我需要一个动态查询,它只获得一个查询作为这些查询。也许用案例?
答案 0 :(得分:0)
问题通过2个查询和一个循环
解决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();
及其全部!只有一个查询..