Jump to content

query problem


boon_chong

Recommended Posts

I'd like to query only the month of stockmovement.date, but when i use stockmovement.month(date) the error come out. Somebody please help me to figure out. Thx.

 

$query = "select distinct employee.itemNo,employee.itemDesc,employee.date,
employee.outlet,stockmovement.barcode,stockmovement.quantity,stockmovement.date 
from employee,stockmovement where 
employee.itemNo =stockmovement.barcode 
group by employee.itemNo";

 

Link to comment
Share on other sites

I'd like to query only the month of stockmovement.date, but when i use stockmovement.month(date) the error come out. Somebody please help me to figure out. thanks.

 

$query = "select distinct employee.itemNo,employee.itemDesc,employee.date,
employee.outlet,stockmovement.barcode,stockmovement.quantity,stockmovement.date 
from employee,stockmovement where 
employee.itemNo =stockmovement.barcode 
group by employee.itemNo";

 

 

I'll just clean it up to focus only on the SQL.

 

SELECT DISTINCT
       employee.itemNo, 
       employee.itemDesc,
       employee.date,
       employee.outlet,
       stockmovement.barcode,
       stockmovement.quantity,
       stockmovement.date
FROM employee, stockmovement
WHERE
       employee.itemNo = stockmovement.barcode,
GROUP BY employee.itemNo

 

Now, I'm not entirely sure what you want. Could you please rephrase? These are two of my interpretations:

 

1) To retreive the records where the stockmovement.date = certain month?

2) You want to convert stockmovement.date into something you can work with in your program logic (ie. via the date object)?

 

If #1, yea, as jcbarr said, the SQL forums'd find you plenty more answers.

Link to comment
Share on other sites

Perhaps if you told us what the error was?

 

My guess is you want to do:

SELECT DISTINCT
       employee.itemNo, 
       employee.itemDesc,
       employee.date,
       employee.outlet,
       stockmovement.barcode,
       stockmovement.quantity,
       stockmovement.date
FROM employee, stockmovement
WHERE
       employee.itemNo = stockmovement.barcode AND
       MONTH(stockmovement.date) = $month_number
GROUP BY employee.itemNo

 

Where $month_number is an integer between 1 and 12, inclusive.

 

@8ball, You have an error in your MySQL query.  Check the manual for the correct syntax to use near "WHERE employee.itemNo = stockmovement.barcode, GROUP BY"  ;^]

Link to comment
Share on other sites

@8ball, You have an error in your MySQL query.  Check the manual for the correct syntax to use near "WHERE employee.itemNo = stockmovement.barcode, GROUP BY"  ;^]

 

Oops! Oh well, I just copied and pasted his and cleaned it up. That comma went right by me! Good eye!

Link to comment
Share on other sites

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.