How can I update Crate IDs of List of Fruits in single SQL query in c#

谁说胖子不能爱 提交于 2019-12-20 03:11:47

问题


In reference to my question,

how can i update SQL table logic

I want a query which will do something like this,

I my last question was confusing hence I am asking a different question.

How can I update Crate IDs of List of Fruits in single SQL query in c#

FruitID and CrateID are foriegn keys and will always in other tables.


回答1:


Try using IN:

UPDATE FRUITS
SET CRATE = 'CRATE 7'
WHERE FRUITID IN (1, 2, 3)

Or

UPDATE FRUITS
SET CRATE = 'CRATE 7'
WHERE FRUITName IN ('Mango1', 'Mango2', 'Apple 6')

You can also use LIKE to match Mango and Orange however this may update the incorrect results (Say you want Orange 199 to be updated to Crate 7 but want Orange 198 to be Crate 6)



来源:https://stackoverflow.com/questions/16539948/how-can-i-update-crate-ids-of-list-of-fruits-in-single-sql-query-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!