sql server - mergin one stored procedure to another in sql -
i have stored procedure this:
alter procedure [dbo].[fetchkey] @carid nvarchar(50) =null begin select t.tbarcode,t.status transaction_tbl t t.tbarcode=@carid end
my output :
tbarcode status 51891044554 1
i want show 1 more column depend upon status.so worte 1 function this:
alter function [dbo].[keyloc](@status numeric(18,0)) returns varchar(50) begin declare @keylocation varchar(50) if @status=1 select @keylocation= e1.ename transaction_tbl t left join employeemaster_tbl e1 on e1.ecode = t.ecode , t.status = 1 or e1.ecode=t.delecode , t.status=4 return @keylocation end
then try execute stored procedure this:
alter procedure [dbo].[fetchkey] @carid nvarchar(50) =null begin select t.tbarcode,[dbo].[keyloc](t.status) transaction_tbl t t.tbarcode=@carid end
but output getting wrong:
tbarcode 51891044554 null
what wrong code? expected output this:
tbarcode status key location 51891044554 1 raheem.
how can this?
problem made left join in function, try this:
select @keylocation= e1.ename transaction_tbl t join employeemaster_tbl e1 on e1.ecode = t.ecode , t.status = 1 or e1.ecode=t.delecode , t.status=4
Comments
Post a Comment