Does SQL (MySQL) support ternary operators?
I have this SQL:
CREATE TEMPORARY TABLE SalesTbl (
CTR int primary key auto_increment,
VRNOA VARCHAR(50),
DESCRIPTION VARCHAR(50),
INQTY INT,
OUTQTY INT,
ETYPE VARCHAR(50),
RTotal DECIMAL(19,2)
);
INSERT INTO SalesTbl
SELECT 0, stockmain.VRNOA AS 'VRNOA', Item.description as 'DESCRIPTION',
qty as 'QTY', Stockmain.etype 'ETYPE', null
FROM StockMain
INNER JOIN StockDetail on StockMain.stid = StockDetail.stid
INNER JOIN ITEM on StockDetail.item_id = Item.item_id
WHERE StockDetail.item_id = 6
AND StockMain.vrdate BETWEEN '2010/10/02' AND '2013/12/02'
ORDER BY Qty;
Would it be possible to do something like this in MySQL?
(QTY < 0) ? QTY : 0
If QTY is less than 0, then use QTY, otherwise use 0.
You need the CASE statement (alternatively there are IF statements but CASE is the standard across many databases) which returns the expression of the first true criteria.
http://dev.mysql.com/doc/refman/5.0/en/case.html