这段时间,需要把一些C#处理的逻辑程序,搬移至SQL的存储过程中去。下面这个例子,就是怎样使用SQL的IN去替换C#的“||”参考代码,cs:
View Code
bool hub = false;
bool store = false;
if (dataRow["Warehouse"].ToString() == "CF3" || dataRow["Warehouse"].ToString() == "CW2")
{
hub = true;
}
else
{
store = true;
}
bool store = false;
if (dataRow["Warehouse"].ToString() == "CF3" || dataRow["Warehouse"].ToString() == "CW2")
{
hub = true;
}
else
{
store = true;
}
这段代码,经Insus.NET移至SQL的存储过程之后,变为:
View Code
DECLARE @Store bit = 0,@Hub bit = 0
IF (@Warehouse IN ('CF3','CW2'))
SET @Hub = 1
ELSE
SET @Store = 1
IF (@Warehouse IN ('CF3','CW2'))
SET @Hub = 1
ELSE
SET @Store = 1
某一天,如果客户在需要添加一个判断,如,"SW1",只需要去存储过程添加一个参数即可:IN ('CF3','CW2','SW1')