我有這樣的storedprcocedure:同時加入case語句得到錯誤的存儲過程
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'
我的功能是這樣的:
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 [email protected]
select @EDT= l.EDT from Location_tbl l where [email protected]
select @minEDT=l.MinEDT from Location_tbl l where [email protected]
select @buffEDT=l.BuffrEDT from Location_tbl l where [email protected]
if (@EDT is null) or (@EDT=0)
begin
select @[email protected][email protected]
end
else
begin
select @[email protected][email protected]
end
return @value
end
所以我的存儲過程的執行時間s slow..so我從我的程序中刪除了我的功能,並且我編寫了如下代碼:
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'
*但出現錯誤: 消息207,級別16,狀態1,行4 無效的列名稱'bufferEdt'。 消息207,級別16,狀態1,行4 無效的列名稱bufferEdt'
我添加額外僅此代碼
的情況下,當l.edt爲空或l.edt = 0,則升。 minEdt + l.bufferEdt else l.edt + l.bufferEdt end to EDT
先生我怎麼可以加入我的功能特定的存儲過程? – user3262364
先生你能否顯示示例代碼? – user3262364
當l.edt爲空或l.edt = 0時,不要在您的select語句使用情況下調用EDTCAL,那麼l.minEdt + l.bufferEdt else l.edt + l.bufferEdt以EDT結束。正如我所說,我正在通過電話進行此操作。我會稍後發佈代碼,但試試這個 –