Jump to content

Str_To_Date Unknown Column Issue


viviosoft

Recommended Posts

Hello -

 

I'm trying to format a date (which works) howerver, I'm getting "Unknown column 'newDate' in 'where clause'"

 

Here's my sql statement:

 

SELECT *, STR_TO_DATE(invDetails.invoiceDate,'%m/%d/%y') AS newDate
	 FROM stores AS store
		 INNER JOIN invoice_details AS invDetails
		 ON store.sCustNum = invDetails.sCustNum
		 WHERE store.sSalesman = 508 AND store.BillToId = 7161
		 AND newDate BETWEEN '2012-01-01' AND '2012-12-31'
		 GROUP BY store.sCustNum

 

Here's the output WITHOUT the BETWEEN logic

 

(
   [id] => 1216
   [billToId] => 7161
   [sCustNum] => VS7121
   [sNumber] => 5263
   [sSalesman] => 508
   [sName] => CIRCLE K PICKERINGTON
   [sAddress] => 29 S HILL RD
   [sCity] => PICKERINGTON
   [sState] => OH
   [sZip] => 43147-1218
   [sPhone] => 6148379337
   [sFax] =>
   [sContact] =>
   [cId] => VS7121
   [invoiceNumber] => 097319
   [repNumber] => 512
   [invoiceDate] => 1/10/11
   [payMethod] => 2
   [invoiceType] =>
   [invoiceHistory] => 1
   [newDate] => 2011-01-10
)

 

Can't think of whatI might be doing wrong... thanks for any help you can provide me.

Link to comment
https://forums.phpfreaks.com/topic/271445-str_to_date-unknown-column-issue/
Share on other sites

Correction... I can use GROUP BY, however I don't think this is the best approach as the Query takes almost 1 minute to complete. Any help would be great.

 

SELECT *, STR_TO_DATE(invDetails.invoiceDate,'%m/%d/%y') AS newDate
	 FROM stores AS store
		 INNER JOIN invoice_details AS invDetails
		 ON store.sCustNum = invDetails.sCustNum
		 GROUP BY store.sCustNum
		 HAVING store.sSalesman = 508 AND store.BillToId = 7161
		 AND newDate BETWEEN '2011-01-01' AND '2011-12-31'

Instead of the alias, try the longhand version of it in the WHERE.

 

SELECT *, STR_TO_DATE(invDetails.invoiceDate,'%m/%d/%y') as newDate
                FROM stores AS store
                        INNER JOIN invoice_details AS invDetails
                        ON store.sCustNum = invDetails.sCustNum
                        WHERE store.sSalesman = 508 AND store.BillToId = 7161
                        AND STR_TO_DATE(invDetails.invoiceDate,'%m/%d/%y') BETWEEN '2012-01-01' AND '2012-12-31'
                        GROUP BY store.sCustNum

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.