我正在尝试创建一个SQL case语句,其中一个then语句将有多个动作。不确定这是否可能,以下查询的这部分( @ItemCountVariable = a.ItemCount + 10)
不起作用,但这正是我想要实现的。
DECLARE @ItemCountVariable INT = 0
...
WHEN MATCHED THEN
UPDATE SET Name = a.Name,
[Description] = a.[Description],
ItemCount =
(CASE WHEN ((a.ItemCount + 10) < 20)
THEN a.ItemCount + 10
ELSE a.ItemCount, @ItemCountVariable = a.ItemCount + 10
END)
...
答案 0 :(得分:1)
正如jarlh在评论中所写,<form method="POST" action="{% url 'account_change_password' %}" class="password_change signup">
{{form.non_field_errors}}
{% csrf_token %}
<p><label for="id_oldpassword">Current Password:</label> <input id="id_oldpassword" name="oldpassword" placeholder="Current Password" type="password" required class="sigup_input"/></p>
<p>{{form.oldpassword.errors}}</p>
<p><label for="id_password1">New Password:</label> <input id="id_password1" name="password1" placeholder="New Password" type="password" required class="sigup_input"/></p>
<p>{{form.password1.errors}}</p>
<p><label for="id_password2">New Password (again):</label> <input id="id_password2" name="password2" placeholder="New Password (again)" type="password" required class="sigup_input"/></p>
<p>{{form.password2.errors}}</p>
<button type="submit" name="action">{% trans "Change Password" %}</button>
</form>
是一种表达,而不是一种陈述
这意味着case返回单个值,不能用作流控制元素。
有关更多信息,请参阅MSDN官方文档中有关case
的相关qoute :(我已加粗相关部分)
备注
SQL Server在CASE表达式中只允许10个级别的嵌套。CASE表达式不能用于控制Transact-SQL语句,语句块,用户定义函数和存储过程的执行流程。有关控制流方法的列表,请参阅Control-of-Flow Language (Transact-SQL).
答案 1 :(得分:0)
跟着BEGIN...END
DECLARE @Iteration Integer = 0;
WHILE @Iteration <10
BEGIN
SELECT FirstName, MiddleName
FROM dbo.DimCustomer WHERE LastName = 'Adams';
SET @Iteration += 1 ;
END;