Re: SQL syntax

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Or is there a better way to check multiple options against an enum inside your select statement?

IN

for example:  orderstatus IN ( 'Cancelled', 'New', 'Denied', 'Expired')

However this is not exactly what you are doing.  You want different orderdate > $yesterday depending on the orderstatus.  A better way might be:

$sql = "SELECT orderid
	        FROM ORDERS_TABLE
	        WHERE orderstatus = 'Cancelled'
                 OR ( orderstatus IN ('New', 'Denied', 'Expired') AND  orderdate < '".mysqli_real_escape_string($yesterday)."')"


> Reason I am doing this is to avoid having to do...
> 
> $sql = "SELECT orderid
> 	        FROM ORDERS_TABLE
> 	        WHERE orderstatus = 'Cancelled' OR (orderstatus = 'New'  AND orderdate < '".mysqli_real_escape_string($yesterday)."') OR (orderstatus = 'Denied'  AND orderdate < '".mysqli_real_escape_string($yesterday)."') OR (orderstatus = 'Expired'  AND orderdate < '".mysqli_real_escape_string($yesterday)."') ... etc";
> 
> TIA,
> 
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux