473,624 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Doubt in querying

40 New Member
I am doing a project on inventory control of grocery items using PHP and mysql 5.In my project i have 2 tables..
1.master_in_out s->where all the inward and outward transactions of particular items are inserted
The fields are->id(primary key)
Item_id
Date
transaction(whe ther inward/outward)
Price
Quantity
Total_amount
Average
supplier_Name(f or inward)
invoice_Number( for inward)
opening_Stock
closing_Stock
2.master_transa ctions->This contains all the available items with/without
transactions... once any transaction occurs,the stock values
gets updated
The fields present are->trans_id(prima ry key)
Item_id
Items
stock
avgPrice
Date
The difference between these 2 tables is that in master_in_outs only the items which are transacted are available but in master_transact ions all the items will be available irrespective of transactions.No w i am getting a problem while generating a transactions report on a particular date..
The report should generate all the items and all the transactions on the given date...
My query is as follows...

select DISTINCT a.Item_id,a.Ite ms,case when a.Item_id=b.Ite m_id then b.opening_Stock else a.stock end as opstock,case when b.transaction=2 then b.Quantity else 0 end as inward,case when b.transaction=1 then b.Quantity else 0 end as outward,case when a.Item_id=b.Ite m_id then b.closing_Stock else a.stock end as clstock from master_transact ions a left join master_in_outs b on a.Item_id=b.Ite m_id AND b.Date=curdate( )
Sep 5 '08 #1
2 1426
r035198x
13,262 MVP
What does your current query give and what did you want it to return instead?
Note also that keeping a current quantity of inventory may not be the best approach. You'd have to update that value after each transaction. Rather always deduce the current quantity by querying the transactions table. Your transactions table could use -q for quantity q issued out and +q for quantity q coming in.
Sep 5 '08 #2
divyac
40 New Member
What does your current query give and what did you want it to return instead?
Note also that keeping a current quantity of inventory may not be the best approach. You'd have to update that value after each transaction. Rather always deduce the current quantity by querying the transactions table. Your transactions table could use -q for quantity q issued out and +q for quantity q coming in.
But i have to show each and every transaction in the report and so i need to keep all the records without appending the values..

Yes i do use +q and -q for inward and outward at the time of insertion...

And now my problem got solved with a simple "where" clause..
select a.Item_id,a.Ite ms,case when a.Item_id=b.Ite m_id then b.preStock else a.stock end as opstock,case when b.transaction=2 then b.Quantity else 0 end as inward,case when b.transaction=1 then b.Quantity else 0 end as outward,case when a.Item_id=b.Ite m_id then b.closing_Stock else a.stock end as clstock from master_transact ions a left join master_in_outs b on a.Item_id=b.Ite m_id and b.Date='curdate ()' where a.Date='curdate ()'....

previously i was getting all the transactions in all dates...Now the problem is solved..I thought i couldnot use "where" if "on"(on a.Item_id=b.Ite m_id and b.Date='curdate ()' ) clause is used...

Thanx for ur reply....
Sep 6 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2249
by: Michael Whittaker | last post by:
Hello! I have a problem with my php script. The script's task is to search an IP-Database with ranges as entries and find, in which range the entered IP is. OK, I've queried the MySQL-Results of the ranges into an array, containing the "IP ==> internalid" where internalid is the Primarykey of the table from which I can get
1
1683
by: Ravi Shankar | last post by:
Hi all, I have a calendar application( like Microsoft Outlook) writtn in Java.Whenever an event is created, we can set SMS/EMAIL notification. Hence when an event is created, I am storing that event info and notification time into a database.Now the notification can be ranging from 5 minutes to say one day.Hence I need to query the databse every 5 minutes and fetch the data and do send the notification directly. I understand that such a...
3
1824
by: Keith | last post by:
I am fairly new to SQL so sorry if this is a really dumb question. I have a small (still) SQL database, which I am trying to query from an ASP page. The field I am querying is of DATETIME data type, and is populated automatically using the GetDate() function as a default value. When I try and search on this field, using a date/time in the format dd/mm/yyyy hh:mm:ss as the search criteria, it fails with the following
1
2090
by: valexena | last post by:
After a few minutes of querying the database my session disconnects abruptly. Can somebody help me and tell why can be happening? -- Posted via http://dbforums.com
6
2648
by: Greg | last post by:
I am working on a project that will have about 500,000 records in an XML document. This document will need to be queried with XPath, and records will need to be updated. I was thinking about splitting up the XML into several XML documents (perhaps 50,000 per document) to be more efficient but this will make things a lot more complex because the searching needs to go accross all 500,000 records. Can anyone point me to some best practices...
5
2365
by: Shane | last post by:
I wonder if someone has any ideas about the following. I am currently producing some reports for a manufacturing company who work with metal. A finished part can contain multiple sub-parts to make up the finished part. The sub-parts can also be made up of sub-parts and those sub-parts can also be made up of sub-parts etc etc. All parts are contained within the same table and I have a seperate table
3
1577
by: MDB | last post by:
I'd normally Google for a question like this, and hope to snag a few examples along with the answer, but this time I can't see to get the keywords specific enough. Or I'd ask coworkers, but they're just as new to ASP.NET as I am. Is it possible to have a dataset filled with all the records in an SQL table (on the small side, maybe three hundred records total), and then query that table for subsets of data, e.q. a simple WHERE clause,...
2
1736
by: RajSharma | last post by:
Hi, I am facing a problem regarding querying thru a large table having millions of rows....... Its hanging in between while querying for all those rows Can anybody suggest me a query regarding : Querying the database everytime for next 100 records ( that means i need to set up a cursor) till the count of the table rows ends up(take 1 million rows e.g.) The database is DB2
4
1522
by: =?Utf-8?B?U3VoYXMgVmVuZ2lsYXQ=?= | last post by:
Hello, I am facing an issue while querying Active directory using C# code with system.DirectoryServices namespace. Here is the path for my LDAP - "LDAP://CN=XY - C++/Unix and other, OU=Automatic,OU=DLs,DC=domain,DC=com"; I have replaced the / character with\/- but still is giving error while querying. Please help me to resolve this.
0
8179
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8633
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8348
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4187
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1797
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.