473,404 Members | 2,174 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,404 software developers and data experts.

How to create a query that combines multiple rows into one and...

Hi there

I am trying to create a database that generates delivery notes. I have an excel spreadsheet linked to the database. From the linked information I need to be able to create a delivery note. But in the table, there are multiple instances of an order number.

Order_No Branch Voucher Code
112 44 5
112 44 10
112 44 20

How can I create a report/delivery note so the data is all on one row...

Order No Branch Voucher Code 1 Voucher Code 2 ...
112 44 5 10 20


I really need some advice...my deadline is tomorrow :(

Thanks in Advance

Simon
Oct 19 '10 #1
11 1652
nico5038
3,080 Expert 2GB
Hi Simon,

For this we have the cross-table query that will make columns out of the Vouchers.

There's however a nasty side effect, as the content of the column will be changed into the column name. When you have no fixed max of vouchers per order, it's hard to create a report, as you won't know how many fields to place...

Do you know the max ?

Nic;o)
Oct 19 '10 #2
Rixxe
7
Perhaps if you post what you have so far in your DB, people might be able to have a look.
(Would make the solution a lot faster, seeing as you have a deadline.)
Would it not be easier, just to import the data into access, rather than link from excel?
Oct 19 '10 #3
Hi guys

Maximum number of voucher types per delivery note is 5.

How do I upload files to this forum? I am new to this unfortunately

Thanks in advance
Oct 19 '10 #4
Rixxe
7
Hi Simon,

http://bytes.com/faq.php?faq=vb3_rea...b3_attachments

Should help you attach your DB.
Oct 20 '10 #5
Hi Guys

Please see attached the database that I am working on

Any help would be hugely appriciated.

Some useful things to note
  • 1 Branch can order many Products
  • I want all the items ordered by the branch on the day that they placed the order to be on 1 document (Delivery Note). This in term means the Order No will appear once on the combined Delivery Note

Thanks in Advance

Simon
Attached Files
File Type: zip Order Database.zip (100.8 KB, 84 views)
Oct 22 '10 #6
nico5038
3,080 Expert 2GB
Try the next query to see how I forced the Products to appear in columns:

Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Max(Order.[Product Code]) AS [MaxOfProduct Code]
  2. SELECT Order.[Order Number], Order.Branch
  3. FROM [Order]
  4. GROUP BY Order.[Order Number], Order.Branch
  5. PIVOT DCount("Date","Order","[Order Number]='" & [Order Number] & "' and [Branch] = '" & [Branch] & "' and [Product Code] <='" & [Product Code] & "'");
  6.  
Some additional work is needed to get the "fixed" 5 columns, but I won't spoil your fun.

Nico
Oct 22 '10 #7
Hi Nico,

The code you wrote worked thanks mate.

Another thing, how would I get the Branch Address fields to appear on the same line as the order/branch?

E.g. Order No, Branch, Address 1, Address 2, P1, P2, P3
(P1,2,3) = Product Value 1 etc)

Thanks again mate

Simon
Oct 22 '10 #8
Hi mate

Thanks for the sending the code...it worked :D

How would I get the Branch Address fields to appear in the same line?

E.g.
Order No, Branch, Address1, Address2, P1, P2, P3

(P1,2,3 - the products associated to the order no)

Thanks again mate...sorry if this question appears twice, I wasnt sure if my last post was sent)

Cheers

Simon
Oct 22 '10 #9
nico5038
3,080 Expert 2GB
Just add them with the same value (Header row) as the two existing fields. When they aren't in the Order table, first JOIN the Customer table.

Nico
Oct 22 '10 #10
Hi Nico

Thanks for your reply

If I wanted to add more fields to the quert for example a No of Vouchers, Number of books, branch address and the Product related fields how would I do this to work in this query?


Sorry to be a pain mate

Cheers

Simon.
Oct 22 '10 #11
nico5038
3,080 Expert 2GB
Check the help description for all possibilities.
There's only one field that's possible as a column header and one for the value. Only the row header allows multiple (group by) fields.
Multiple field values will require multiple queries or tricky querying.

Nico
Oct 22 '10 #12

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

Similar topics

7
by: RotterdamStudents | last post by:
Hello there, i have a strange problem. I can't get php to insert multiple rows at once in a MySQL database. I use the $sql = "INSERT INTO database (a,b,c,d,e) VALUES ('$a', '$b' ,'$c', '$d',...
4
by: don.fleming | last post by:
Hi folks: Am doing a VBA SQL Select stmt with multiple rows found and not getting RecordCount > 1. I've verified there are multiple rows found by copying my SQL stmt from Debug window and pasting...
5
by: Arsen V. | last post by:
Hello, What is the optimal way to insert multiple rows (around 1000) from a web application into a table? The user enters multiple lines into a text box (up to 10,000). The ASP.NET...
2
by: ameshkin | last post by:
I know this is probably not too hard to do, but how do I display multiple rows of a mysql query/recordset. Im having trouble doing this. I don't just want to display them, but I want to make sure...
9
by: kencana | last post by:
Hi all, I am a new bie in SOAP and PHP.I got one question about the data retrieval. I am able to retrieve the data successfully from my database. this is my sql statement: select roadname from...
12
by: Michel Esber | last post by:
Hello, Db2 Linux LUW FP 15. Consider table A (ID varchar, EXECUTION_DATE date). a) I want to first retrieve all IDs that have not executed during the last 90 days: select distinct ID...
1
by: gerbrandc | last post by:
Hello, how can I insert into the sql compact edition 3.5 multiple rows. I have following query INSERT INTO network (name, adname, timezone) VALUES ('rm', 'rm', 1), ('pm', pm', 1) , ...
9
WyvsEyeView
by: WyvsEyeView | last post by:
I have a form that has four unbound combo boxes: cboType, cboVersion, cboStatus, cboReview. I want to write a query that basically lets users make selections in as many combo boxes as apply...only...
0
bilibytes
by: bilibytes | last post by:
hi, i am trying to UPDATE multiple rows with mysql. I know how to do it with multiple queries but i think it would be less resource consuming generating mysql query code with php and update all...
1
by: cronk005 | last post by:
I am fairly new to Database creation and have devised a nice database which does what I am hoping to do. Though I am sure there is an easier way of accomplishing many of the tasks I have done, as I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...
0
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,...
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...

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.