對不起,如果這將是一個愚蠢的問題,這是我第一次使用SQL存儲過程。問題很簡單 - 我如何聲明SELECT語句中的語句?爲了說明我的意思,這裏是一個代碼,我目前有:SQL存儲過程如果語句在選擇
INSERT INTO @trAll
SELECT tr.EventDateTime
,tr.OrderId
,'EX'
,round(tr.Prod01_CompB_QuantityPV_LTR + tr.Prod01_Fuel_QuantityPV_LTR,0)
,tr.eAD
,tr.OperatorName
--
,cmr.ConsigneeName
,cmr.ConsigneeCompanyCode
,cmr.SenderName
,cmr.SenderCompanyCode
FROM vwTransaction AS tr
inner join tbOrderDetailCMR as cmr
on tr.orderid = cmr.OrderId
WHERE tr.EventDateTime BETWEEN @From
AND @to
AND ProductName = 'BIODIESELZ'
這也是我需要什麼(希望你能明白我的意思):
INSERT INTO @trAll
SELECT tr.EventDateTime
,tr.OrderId
,'EX'
,round(tr.Prod01_CompB_QuantityPV_LTR + tr.Prod01_Fuel_QuantityPV_LTR+ (if (tr.Prod01_AdditiveA>0) THEN tr.Prod01_AdditiveA ELSE tr.Prod01_AdditiveB),0)
,tr.eAD
,tr.OperatorName
--
,cmr.ConsigneeName
,cmr.ConsigneeCompanyCode
,cmr.SenderName
,cmr.SenderCompanyCode
FROM vwTransaction AS tr
inner join tbOrderDetailCMR as cmr
on tr.orderid = cmr.OrderId
WHERE tr.EventDateTime BETWEEN @From
AND @to
AND ProductName = 'BIODIESELZ'
總之我需要的是添加AdditiveA(如果它的值大於0),否則AdditiveB在select語句中。
哪些DBMS您使用的? –