473,408 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

select sql query problem

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=sttakedm.queue_reference 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_number, sttakedm.product_code, sttakedm.adjustment_quantit, sttakedm.expected_quantity, sttakehm.warehouse, stquem.unit_cost, sttakehm.description1
FROM scheme.sttakedm sttakedm

INNER JOIN scheme.sttakehm on sttakehm.card_number = sttakedm.card_number
LEFT OUTER JOIN scheme.stquem on sttakehm.warehouse=stquem.warehouse

WHERE sttakehm.card_number = sttakedm.card_number AND sttakedm.card_number='C03323' AND (stquem.sequence_number=sttakedm.queue_reference OR (sttakedm.kind = 'B' OR sttakedm.kind = 'C')) AND sttakedm.product_code = stquem.prod_code AND sttakehm.warehouse=stquem.warehouse
Dec 9 '11 #1
10 1793
Rabbit
12,516 Expert Mod 8TB
Sample data and results would help. I have trouble understanding what you're asking.
Dec 9 '11 #2
@Rabbit
Hi The result is coming like this:
Stock Variance Template

card_number description1 warehouse product_code adjustment_quantit expected_quantity 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_quantit expected_quantity
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_inspection 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
[quote=Rabbit;3690606]Sample data and results would help. I have trouble understanding what you're asking.[/
Dec 9 '11 #4
@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 Expert Mod 8TB
I see the sample data but I don't see the results.
Dec 9 '11 #6
@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 Expert Mod 8TB
Can you paste the results in a post? I prefer not to download files from unknown sources.
Dec 11 '11 #8
Hi

Here is the Result:
card_number description1 warehouse product_code adjustment_quantit expected_quantity 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
In the above result for
Card_number is : Card03323
description1: STOCK TAKE 01 DEC 2011
warehouse: FG
product_code: 0015
adjustment_quantit: 0
expected_quantity: 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_quantity & one adjustment_quantit for one product_code
Dec 11 '11 #10
Rabbit
12,516 Expert Mod 8TB
And how do you know which adjustment quantity and product code to take? If there's multiple and you only want one, you need an algorithm to choose one.
Dec 12 '11 #11

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

Similar topics

2
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...
1
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
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
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
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
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
by: narendrashete | last post by:
I have Two Tables Tabel 1 is Purchase prodcode billno billdate quantity
3
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...
6
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...
1
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

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.