i have a storedprcocedure like this:
SELECT
k.HBarcode, m.make,t.Compl,
t.plateno,t.self,t.dtime, v.vtype, l.locname,[dbo].[EDTCAL](t.TBarcode)as EDT, t.locid,t.vtid,t.lsttic,
c.Colname, te.UniqueName
FROM transaction_tbl t
left JOIN KHanger_tbl k ON t.transactID = k.transactID
left JOIN make_tbl m ON t.mkid = m.mkid
left JOIN vtype_tbl v ON v.vtid = t.vtid
left JOIN Location_tbl l ON t.locid = l.locid
left JOIN Color_tbl C ON t.colid = c.colid
left JOIN Terminals_tbl te ON k.tid = te.tid
WHERE t.tbarcode = '0213'
my function like this:
ALTER function [dbo].[EDTCAL](@cardID VARCHAR(50)) RETURNS int
as
begin
declare
@locid int,
@EDT int,
@minEDT int,
@buffEDT int,
@value int
select @locid= t.Locid from Transaction_tbl t where t.TBarcode=@cardID
select @EDT= l.EDT from Location_tbl l where l.Locid=@locid
select @minEDT=l.MinEDT from Location_tbl l where l.Locid=@locid
select @buffEDT=l.BuffrEDT from Location_tbl l where l.Locid=@locid
if (@EDT is null) or (@EDT=0)
begin
select @value=@minEDT+@buffEDT
end
else
begin
select @value=@EDT+@buffEDT
end
return @value
end
so my stored procedure execution time s slow..so i removed my function from my procedure and i wrote code like this:
SELECT
k.HBarcode, m.make,t.Compl,
t.plateno,t.self,t.dtime, v.vtype, l.locname,case when l.edt is null or l.edt =0 then l.minEdt +l.bufferEdt else l.edt + l.bufferEdt end as EDT, t.locid,t.vtid,t.lsttic,
c.Colname, te.UniqueName
FROM transaction_tbl t
left JOIN KHanger_tbl k ON t.transactID = k.transactID
left JOIN make_tbl m ON t.mkid = m.mkid
left JOIN vtype_tbl v ON v.vtid = t.vtid
left JOIN Location_tbl l ON t.locid = l.locid
left JOIN Color_tbl C ON t.colid = c.colid
left JOIN Terminals_tbl te ON k.tid = te.tid
WHERE t.tbarcode = '0213'
*but getting error :
Msg 207, Level 16, State 1, Line 4
Invalid column name 'bufferEdt'.
Msg 207, Level 16, State 1, Line 4
Invalid column name 'bufferEdt'
i added extra only this code
case when l.edt is null or l.edt =0 then l.minEdt +l.bufferEdt else l.edt + l.bufferEdt end as EDT