存储过程 If/Then 语句 [英] Stored Procedure If / Then Statement
本文介绍了存储过程 If/Then 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们正在尝试实现密码间隔,如果有的话.
We are trying to implement a password interval, if there is one.
如果 sm_Setting(PasswordExpireDays) 有一个值,我们就使用它.如果没有,请继续
If sm_Setting(PasswordExpireDays) has a value, we use it. If not, continue on
CREATE Procedure user_password_date_interval_check
@ua_pk uniqueidentifier
AS
DECLARE @PasswordExpireDays int
SET @PasswordExpireDays = 0
SELECT
sm_Setting, sm_Value
FROM
Setting_Misc AS sm
INNER JOIN
Syndicates As syn ON sm.syn_fk = syn.syn_pk
INNER JOIN
Company As c ON c.syn_fk = syn.syn_pk
INNER JOIN
User_Accounts As ua ON ua.c_fk = c.c_pk
WHERE
sm.sm_Setting = 'PasswordExpireDays'
THEN sm.sm_Value = @PasswordExpireDays
我在使用 WHERE
子句时遇到问题.我试过CASE
.底线是,这一行(基于 PK 和设置),我想从 Value
列中获取值.
I'm having issues with the WHERE
clause. I have tried CASE
. Bottom line is, this row (based on a PK and Setting), I want to grab the value from the Value
column.
推荐答案
CREATE Procedure user_password_date_interval_check
@ua_pk uniqueidentifier
AS
DECLARE @PasswordExpireDays int
SELECT
--sm_Setting,
@PasswordExpireDays =COALESCE(sm_Value,0)
FROM
Setting_Misc AS sm
INNER JOIN
Syndicates As syn
ON sm.syn_fk = syn.syn_pk
INNER JOIN
Company As c
ON c.syn_fk = syn.syn_pk
INNER JOIN
User_Accounts As ua
ON ua.c_fk = c.c_pk
WHERE sm.sm_Setting = 'PasswordExpireDays'
--@PasswordExpireDays is either default 0 or the value from the table if not null.
这篇关于存储过程 If/Then 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文