Sql server ce 在一个查询中有很多更新(同一列),如何进行此动态查询?
我有以下疑问:Sql server ce 在一个查询中有很多更新(同一列),如何进行此动态查询?,sql-server-ce,Sql Server Ce,我有以下疑问: 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
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,我无法发送所有查询,只能一个接一个地发送
需要花费很多时间,所以我需要一个动态查询,它只会得到一个与这些查询一样工作的查询。也许是用例 问题通过两次查询和一次循环解决
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'
)
我可以使用ExecuteOnQuery;就这样!只有一个问题。背后的逻辑是什么?我在这里找不到模式…循环获取productsid和添加到Quantity的值唯一的方法是绕过查询处理器并使用TableDirect和SqlCeUpdateableRecord