【发布时间】:2013-12-06 04:52:21
【问题描述】:
我有这张桌子Components:
ItemNo ItemDescription Type
1 Apple Fruit 20Kg null
2 Carrot Veg 1Kg null
3 Fig DryFruit 100g null
要求是,对于每个ItemDescription,我确定它是Fruit 还是DryFruit,我将值fruit 插入到列Type 中。如果它的类型是Veg,那么我将值Vegetable 放入列Type。
结果表如下所示:
ItemNo ItemDescription Type
1 Apple Fruit 20Kg Fruit
2 Carrot Veg 1Kg Vegetable
3 Fig DryFruit 100g Fruit
我如何做到这一点?
使用 C# 代码:
var itemDescription = GetAllItemDescription() //Executes 'select ItemDescription from Components;' SQL query
itemDescription.ForEach(item=>{
if(item.Contains("Fruit") || item.Contains("DryFruit"))
{
EnterFruitInTypeColumn() //contains sql query which does the corresponding stuff.
}
........
}
问题是:
我应该如何只使用 SQL 语句来做同样的事情?
(我也知道有T-SQLstring processing stuffs,但是不能满足上面的要求)
【问题讨论】:
-
@bryanmac:不错的收获!但是,我 100% 确定这不会发生。它可以是
Refreshing Vegetable drink或Refreshing fruit dring,但不能同时是两者。 (我负责将数据插入表中,这就是我确定的原因)。但是,这是一个很好的收获。
标签: c# sql .net sql-server sql-server-2008