我想验证该客户是否存在员工;如果他确实存在,那么我想要显示一条消息"成功",否则我想显示"无效的员工"。
declare @Employeeid int
if @Employeeid = 1616
select
@Employeeid = employeeindex
from
Employee_table
where
clientid in (select Clientid
from Employee_table
where Clientid = 658)
select *
from Employee_table
where Employeeid = @Employeeid
else
raiserror ('Invalid Employee!', 16, 1)
return
这显示错误
关键字'其他'附近的语法不正确。
答案 0 :(得分:1)
包含一系列Transact-SQL语句,以便可以执行一组Transact-SQL语句。 BEGIN
和END
是流控制语言关键字。
查询
declare @Employeeid int
if @Employeeid = 1616
begin
select @Employeeid = employeeindex
from Employee_table
where clientindex in (select Clientid
from Employee_table
where Clientid = 658)
select *
from Employee_table
where Employeeid = @Employeeid
end
else
raiserror ('Invalid Employee! ', 16,1)
return
答案 1 :(得分:0)
https://docs.microsoft.com/en-us/sql/t-sql/language-elements/if-else-transact-sql
强制执行Transact-SQL语句的条件。的的 遵循IF关键字的Transact-SQL语句及其条件是 如果条件满足则执行:布尔表达式返回 TRUE
如果需要IF的组声明
,请使用BEGIN ... END