我有这样的存储过程:
ALTER procedure [dbo].[fetchkey]
@carid nvarchar(50) =null
as
begin
select t.TBarcode, t.Status, [dbo].[keyloc](t.Status) as 'Key location'
from Transaction_tbl t
where t.TBarcode=@carid
end
我也有一个这样的功能:
ALTER function [dbo].[keyloc](@status numeric(18,2)) RETURNS varchar(50)
as
begin
declare
@Ename nvarchar(50),
@keylocation Varchar(50)
if @status= 1
select @Ename= e1.Ename from Transaction_tbl t
join EmployeeMaster_tbl e1
ON t.Ecode=e1.Ecode
select @keylocation='With PAIC'+'('+@Ename+')'
return @keylocation
if @status= 4
select @Ename= e2.Ename from Transaction_tbl t
join EmployeeMaster_tbl e2
ON t.DelEcode=e2.Ecode
select @keylocation='With Driver'+'('+@Ename+')'
return @keylocation
end
如果状态 = 4,那么我得到的 keylocation 为空。如果状态为 1,那么答案是正确的,我的代码有任何问题。
请帮我找出解决方案