存储过程 变量
CREATEPROCEDURE[dbo].[sp_basic_salary]ASdeclare@employeevarchar(20)select@employee=em...
CREATE PROCEDURE [dbo].[sp_basic_salary]
AS
declare @employee varchar(20)
select @employee = employee_id from employee
if((select off_probation from employee where employee_id=@employee)= 'Y',
(select employee_id, name, confirm_salary from employee where employee_id=@employee),
(select employee_id ,name ,probation_salary from employee where employee_id =@employee))
对吗这样写? 展开
AS
declare @employee varchar(20)
select @employee = employee_id from employee
if((select off_probation from employee where employee_id=@employee)= 'Y',
(select employee_id, name, confirm_salary from employee where employee_id=@employee),
(select employee_id ,name ,probation_salary from employee where employee_id =@employee))
对吗这样写? 展开
展开全部
你没测试?你这存过无传入、输出参数,只有内部参数;并且有可能无法正常运行.
--如下定义的变量生存周期只限于本次批处理;
declare @employee varchar(20)
--如下如果employee 返回ID不只一个会出错
select @employee = employee_id from employee
-----------如下你想实现什么操作?
if((select off_probation from employee where employee_id=@employee)= 'Y',
(select employee_id, name, confirm_salary from employee where employee_id=@employee),
(select employee_id ,name ,probation_salary from employee where employee_id =@employee))
--如下定义的变量生存周期只限于本次批处理;
declare @employee varchar(20)
--如下如果employee 返回ID不只一个会出错
select @employee = employee_id from employee
-----------如下你想实现什么操作?
if((select off_probation from employee where employee_id=@employee)= 'Y',
(select employee_id, name, confirm_salary from employee where employee_id=@employee),
(select employee_id ,name ,probation_salary from employee where employee_id =@employee))
追问
只是提示 if 从句里面 逗号附近有语法错误 最后括号 也有错误 别的没有提示啊 输入入、 一个 employee_id 如果 这个id 下的 off_probation 是 Y 返回 confirm_salary 否则返回 probation_salary
追答
语法上错误很严重.
select @employee = employee_id from employee你没加条件返回的可能不止一个值,
SQL SERVER是不允许把一个子查询返回多值赋值给一个变量;
下面换成:不知道你这段代码要的是不是如下判断执行过程?
if((select off_probation from employee where employee_id=@employee)= 'Y')
--='Y'执行如下:
BEGIN
select employee_id, name, confirm_salary
from employee
where employee_id=@employee
END
ELSE--否则执行:
select employee_id ,name ,probation_salary
from employee
where employee_id =@employee
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询