Jump to content

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.

Edited by viviosoft
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'

Edited by viviosoft

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.