Welcome Guest, Not a member yet? Register   Sign In
Named variables in sql query
#3

(This post was last modified: 06-26-2021, 03:09 AM by stepgr.)

(06-26-2021, 01:51 AM)InsiteFX Wrote: Try this, not tested but fixes some errors in your code see the quotes and semi-colons at the end.
PHP Code:
$sql 'SELECT
MONTHNAME (itd.DateOfshippment) AS Month
,COUNT(itm.Name) AS Operations
FROM ImportsMaster itm
INNER JOIN ImportsDetails itd on itm.ID  = itd.IDMSTR
WHERE itd.Market IS NOT NULL
AND itm.Trader LIKE "%TEXT%"
AND itd.DateOfshippment between :start: and :end:
GROUP BY MONTH(itd.DateOfshippment);'


Thanks  but the profiler still returns the Confusedtart:  :end: in the query instead of actual values :

Code:
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':start: and :end: GROUP BY MONTH(itd.DateOfshippment)' at line 8

SELECT MONTHNAME (itd.DateOfshippment) AS Month ,COUNT(itm.Name) AS Operations FROM ImportsMaster itm INNER JOIN ImportsDetails itd on itm.ID = itd.IDMSTR WHERE itd.Market IS NOT NULL AND itm.Trader LIKE "%TEXT%" AND itd.DateOfshippment between :start: and :end: GROUP BY MONTH(itd.DateOfshippment);

I think it should return the actual values from the post data  eg 2021-01-01 instead  of :start:  or not ?

Never mind I found a way to do it with active record actually and some php logic in between . I wanted also same
CASE WHEN conditions and finally it was much easier with active record
Thanks Anyway !!
Reply


Messages In This Thread
Named variables in sql query - by stepgr - 06-26-2021, 01:03 AM
RE: Named variables in sql query - by InsiteFX - 06-26-2021, 01:51 AM
RE: Named variables in sql query - by stepgr - 06-26-2021, 02:17 AM
RE: Named variables in sql query - by InsiteFX - 06-26-2021, 05:41 AM
RE: Named variables in sql query - by stepgr - 06-29-2021, 06:42 AM
RE: Named variables in sql query - by includebeer - 06-29-2021, 05:41 PM
RE: Named variables in sql query - by php_rocs - 06-30-2021, 06:17 AM



Theme © iAndrew 2016 - Forum software by © MyBB