473,671 Members | 2,340 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

select sql query problem

7 New Member
I hope you can help me.

I am trying to generate a report using 3 tables - sttakehm, sttakedm and stquem.

I wrote below query but it is giving all values of unit_cost, I only need the unit cost which matches stquem.sequence _number=sttaked m.queue_referen ce and adjustment quantit.

The key is sequence number is in one line with Kind = "C" and adjustment quanity is on second line with Kind = "B".

I need this pretty urgent, I hope you can help me

SELECT sttakedm.card_n umber, sttakedm.produc t_code, sttakedm.adjust ment_quantit, sttakedm.expect ed_quantity, sttakehm.wareho use, stquem.unit_cos t, sttakehm.descri ption1
FROM scheme.sttakedm sttakedm

INNER JOIN scheme.sttakehm on sttakehm.card_n umber = sttakedm.card_n umber
LEFT OUTER JOIN scheme.stquem on sttakehm.wareho use=stquem.ware house

WHERE sttakehm.card_n umber = sttakedm.card_n umber AND sttakedm.card_n umber='C03323' AND (stquem.sequenc e_number=sttake dm.queue_refere nce OR (sttakedm.kind = 'B' OR sttakedm.kind = 'C')) AND sttakedm.produc t_code = stquem.prod_cod e AND sttakehm.wareho use=stquem.ware house
Dec 9 '11 #1
10 1811
Rabbit
12,516 Recognized Expert Moderator MVP
Sample data and results would help. I have trouble understanding what you're asking.
Dec 9 '11 #2
rajkrishna
7 New Member
@Rabbit
Hi The result is coming like this:
Stock Variance Template

card_number description1 warehouse product_code adjustment_quan tit expected_quanti ty unit_cost
C03323 STOCK TAKE 01 DEC 2011 FG 0015 0 0 16.9774
C03323 STOCK TAKE 01 DEC 2011 FG 0015 0 144 16.8842
C03323 STOCK TAKE 01 DEC 2011 FG 0015 0 144 16.8968
C03323 STOCK TAKE 01 DEC 2011 FG 0015 0 144 16.9774

Sample data from sttakedm table is:

card_number kind sequence_number queue_reference product_code bin_location status batch_code lot_number adjustment_quan tit expected_quanti ty
C03323 C 000005 P3kKh! 0030 0 0
C03323 B 000005 0030 A100 -35 107
C03323 S 000005 0030 A100 0 0
And sample data from stquem table is:

warehouse product sequence_number prod_code serial_number batch_number date_received bin_number lot_number expiry_date passed_inspecti on inspector_code inspection_date source_code conformity_ref quantity quantity_free unit_cost
FG 0030 P.*qc! 0030 P15506 29/09/2011 0:00 A100 5193 Y 016593 0 0 38.9062
0 32.0154
FG 0030 MA##G! 0030 P00444 11/02/2005 0:00 A100 000493/001 Y 000493 0 0 32.0154
FG 0030 MAhy`! 0030 P00491 18/02/2005 0:00 A100 000551/001 Y 000551 0 0 32.0154
FG 0030 NgOaL! 0030 P09738 19/06/2008 0:00 A100 010345/001 Y 010345 0 0 32.0154
FG 0030 Nii>A! 0030 P09896 10/07/2008 0:00 A100 010508/001 Y 010508 0 0 32.0154

table sttakehm is only used to create card number and for which warehouse. There is no data from that table. It is used only to link card number, warehouse and description.

I hope this helps.
Dec 9 '11 #3
rajkrishna
7 New Member
[quote=Rabbit;36 90606]Sample data and results would help. I have trouble understanding what you're asking.[/
Dec 9 '11 #4
rajkrishna
7 New Member
@Rabbit
HI

I have put excel data in zip file.Hope this helps
Attached Files
File Type: zip Book3.zip (4.19 MB, 61 views)
Dec 9 '11 #5
Rabbit
12,516 Recognized Expert Moderator MVP
I see the sample data but I don't see the results.
Dec 9 '11 #6
rajkrishna
7 New Member
@Rabbit
Hi

I have attached Book3 zip file. In that file tabs stock variance templates are results and tabs-stquem and sttakedm are sample data from tables.
Dec 9 '11 #7
Rabbit
12,516 Recognized Expert Moderator MVP
Can you paste the results in a post? I prefer not to download files from unknown sources.
Dec 11 '11 #8
rajkrishna
7 New Member
Hi

Here is the Result:
card_number description1 warehouse product_code adjustment_quan tit expected_quanti ty unit_cost
C03323 STOCK TAKE 01 DEC 2011 FG 0015 0 0 16.9774
C03323 STOCK TAKE 01 DEC 2011 FG 0015 0 144 16.8842
C03323 STOCK TAKE 01 DEC 2011 FG 0015 0 144 16.8968
C03323 STOCK TAKE 01 DEC 2011 FG 0015 0 144 16.9774
Dec 11 '11 #9
rajkrishna
7 New Member
In the above result for
Card_number is : Card03323
description1: STOCK TAKE 01 DEC 2011
warehouse: FG
product_code: 0015
adjustment_quan tit: 0
expected_quanti ty: 144
unit_cost: different batch cost - 16.9774, 16.8842, 16.8968 & 16.9774

Hope this explain. I need a query which give me one unit_cost and one expected_quanti ty & one adjustment_quan tit for one product_code
Dec 11 '11 #10

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

Similar topics

2
2039
by: Jan Nordgreen | last post by:
I use php4 and winxp. This query works as expected: $result = mysql_query(" SELECT feventid, UNIX_TIMESTAMP(fdate) as fdate, ftitle, fpostedby, fdetails, factive, UNIX_TIMESTAMP(fpostdate) as fpostdate FROM events WHERE fdate between '$datefrom' and '$dateto'
1
1564
by: Roberto Esposito | last post by:
HI to All.... i need an help for a Select Query MYSQL Version 3.23.58 it's all day i try to resolve this problem.... but i don't find SOLUTION! sigh :-( This is the simple query.....
1
1128
by: Craig Keightley | last post by:
I have the following table: id | supRef | pmRef | status | ===================== 1 | 1 | 1 | 3 | 2 | 1 | 2 | 2 | 3 | 1 | 3 | 2 | 4 | 1 | 4 | 3 | 5 | 2 | 1 | 2 |
1
1130
by: Ravman | last post by:
How can I create a query that would find an employees first and last name that begins with the same letter? Thank you in advance.
2
1206
by: Ravman | last post by:
How could I create a "select query" in Access that would find an employee whose first and last name begin with the same letter? Fields: Fname, Lname Table name: employee Thank you in advance.
2
3560
by: Bernd Hohmann | last post by:
Dear collegues, small query problem. A table (simplified example)... customer as char(5) inv_date as date amount as double
6
1385
by: narendrashete | last post by:
I have Two Tables Tabel 1 is Purchase prodcode billno billdate quantity
3
9114
by: RAG2007 | last post by:
I'm using the QueryDef and Execute method to update a record in my MySQL backend. Problem: When the Passthrough update query is defined using QueryDef, it becomes a select query, and I cannot use the Execute Method. Instance: The following code is defined as a query called "AddCost" UPDATE tblinitiative SET tblinitiative.Estimate = " & Estimate & ", tblinitiative.FinalCost = " & FinalCost & " WHERE (((tblinitiative.InitID)=" & InitID &...
6
1566
by: Proaccesspro | last post by:
Hello All, I have a report that is tied to a SELECT query.....Problem is, when I open the report, it also opens the results of the select query. Is there a way to supress the Query from displaying the reults??? DoCmd.openquery "qryETS Open orders", (WHAT GOES HERE?)
1
1634
by: atishrg | last post by:
Hello All, I am facing one strange problem.. I am using a select query in my function which will return specified product details according to product code selected by user.. here is the query.. Select p_code,p_desc from P_St where p_code = '" + cbotext + "' for all other code selected by user it is working fine ..but when user selected a procuct code as 'c9721comp' its failed ,, when I write a select query using Like
0
8473
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8911
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...
1
8597
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
8667
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
5692
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
4222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4402
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2808
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2048
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.