我有叫FL_virtual某種標識的表,如果該標誌等於1,我需要用一個函數來獲取我的股票以特殊的方式條件選擇多個字段
現在我想和select語句間,但根據這個標誌,我需要調整我的選擇使用某種功能,而不是一個子查詢
如此推定的我開始與這個select語句
select product_name,..(other options from the product table), (select sum(qy_stock) from STOCK where warehouse_id = 1) as 'qy_stock_internal', (select sum(qy_stock) from STOCK where warehouse_id = 2) as qy_stock_external From product
現在我需要改變的S ubquery(qy_stock)具有對函數的調用時fl_virtual標誌爲1
,使其變成這樣
select product_name,..(other options from the product table), FN_GET_stock_PRODUCT(1) as qy_stock_internal, FN_GET_stock_PRODUCT(2) as qy_stock_external from product
,所以我想一個簡單的,如果再else結構將做,但出於某種原因我不能讓它的工作 這是我認爲它看起來
select product_name,..(other options from the product table),
IF fl_virtual > 0 THEN
(select sum(qy_stock) from STOCK where warehouse_id = 1) as 'qy_stock_internal',
(select sum(qy_stock) from STOCK where warehouse_id = 2) as qy_stock_external
ELSE
FN_GET_stock_PRODUCT(1) as qy_stock_internal,
FN_GET_stock_PRODUCT(2) as qy_stock_external
END IF
,但它不工作,任何人有一個想法?
非常感謝你! – user1002761