我需要编写一个更新,它接受用户输入文本(下面)并运行有效的更新(需要这样做)。我认为我需要使用某种类型的循环或游标。 引用列可能有其他文本而不仅仅是'FUEL =?'。用户知道格式必须是'FUEL =?'这个更新工作。我目前无法在表中添加添加列。我是新来的...感谢您的帮助!
燃料组= A,C
新附加费= 2
update tblroutes
set DriverSurcharge = 2
where Reference like '%FUEL=A%' or Reference like '%FUEL=C%'
RouteID |参考|收费
F01 | Windows FUEL = A | 0
F02 | FUEL = A | 0
F03 | FUEL = B | 0
F04 |赢8燃料= B | 0
F05 | FUEL = C | 0
F06 | FUEL = C MAC | 0
F07 | FUEL = D | 0
RouteID |参考|收费
F01 | Windows FUEL = A | 2
F02 | FUEL = A | 2
F03 | FUEL = B | 0
F04 |赢8燃料= B | 0
F05 | FUEL = C | 2
F06 | FUEL = C MAC | 2
F07 | FUEL = D | 0
我可以让1'燃料组'一次更新,但希望让用户能够一次性将更新运行到任意数量的组。
DECLARE @Surcharge INT
DECLARE @Group Varchar
--This will give the user a input box for surcharge amount
--SET @Surcharge= '<< Please enter surcharge amount. >>'
----This will give the user a input box for fuel group(s)
--SET @Group= '<< Please enter fuel group(s). >>'
--If the user entered 4 & A
SET @Surcharge= '4'
SET @Group= 'A'
update tblroutes
set DriverSurcharge = @Surcharge
where Reference like '%FUEL='+@Group+'%'
现在,如果用户输入Fuel Group = A,C
,我该如何处理答案 0 :(得分:0)
如果我理解正确,你的主要问题是解析SQL中的用户输入。 解析实际上意味着拆分字符串。只要在临时表或表变量中有单独的值,就可以在循环中运行(已创建的)查询。