|
-
Oct 13th, 2011, 07:50 AM
#1
Thread Starter
Member
[RESOLVED] [Help] SQL for Datareport Complex Query
Hi to all.
I need some help with my project.
I have a database that contain 4 tables: Items, Purchased, Sold, Stocks
I want to make a recordset from these database.
The Items database contains Item Information: BarCode, Name, Size, Price, Category
The Purchased database records Purchase ordered Items: BarCode, Units, Date
The Sold database records Sold out Items: Barcode, Units, Date
The Stocks database records available Items in stock: Barcode, Units, Date
I wanted to query the Database to get a result like this:
Code:
Items.Barcode - Items.Name - Items.Size - Sold.Units
But Sold database contains records with the same Barcode but different Date and Units. So I am looking for a way to automatically add Unit from records with same Barcode in a span of days.
I will need the result to display in a datareport.
I also want it in order by category.
I hope someone can help.
-
Oct 13th, 2011, 11:28 AM
#2
Addicted Member
Re: [Help] SQL for Datareport Complex Query
 Originally Posted by ayankent
Hi to all.
I need some help with my project.
I have a database that contain 4 tables: Items, Purchased, Sold, Stocks
I want to make a recordset from these database.
The Items database contains Item Information: BarCode, Name, Size, Price, Category
The Purchased database records Purchase ordered Items: BarCode, Units, Date
The Sold database records Sold out Items: Barcode, Units, Date
The Stocks database records available Items in stock: Barcode, Units, Date
I wanted to query the Database to get a result like this:
Code:
Items.Barcode - Items.Name - Items.Size - Sold.Units
But Sold database contains records with the same Barcode but different Date and Units. So I am looking for a way to automatically add Unit from records with same Barcode in a span of days.
I will need the result to display in a datareport.
I also want it in order by category.
I hope someone can help.
don't understand your problem - the bit in bold - what actually do you mean?
G
-
Oct 13th, 2011, 11:34 AM
#3
Re: [Help] SQL for Datareport Complex Query
What is the database it makes a difference in what kind of SQL you will run. It sounds like you are mixing terms here also is Stocks a table or a database?
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 14th, 2011, 12:49 AM
#4
Thread Starter
Member
Re: [Help] SQL for Datareport Complex Query
oh... sorry.. its all a table in a single database...
But Sold database contains records with the same Barcode but different Date and Units. So I am looking for a way to automatically add Unit from records with same Barcode in a span of days.
Sold table cantains records with same Barcode but in different date and units.
I am looking for a query that will automatically add the Units with same Barcode in a specified span of date...
-
Oct 14th, 2011, 02:54 AM
#5
Re: [Help] SQL for Datareport Complex Query
Thread moved to the 'Database Development' forum - which is where you should always post SQL questions (while SQL can be used in VB, it is certainly not specific to VB)
-
Oct 14th, 2011, 05:06 AM
#6
Thread Starter
Member
Re: [Help] SQL for Datareport Complex Query
sorry sir... and thanks...
-
Oct 14th, 2011, 07:23 AM
#7
Re: [Help] SQL for Datareport Complex Query
Once again what is the backend datadase? MS Access? SQL Server? Oracle? MySQL?
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 14th, 2011, 10:19 AM
#8
Thread Starter
Member
Re: [Help] SQL for Datareport Complex Query
MS Access...
I am using DataEnvironment to populate the Datareport (VB6)
Example on the table Sold there are these data:
Code:
8851717200014 - 5 - 10/14/2011
8851717200015 - 5 - 10/14/2011
8851717200018 - 5 - 10/14/2011
8851717200014 - 3 - 10/15/2011
8851717200015 - 4 - 10/15/2011
8851717200018 - 3 - 10/15/2011
8851717200014 - 2 - 10/16/2011
the Items table contains some info about the 3 products.
Code:
Barcode - Item Name - Size - Price - Category
8851717200014 - Strawberry Yogurt - 90ml - 18.00 - Beverages
8851717200015 - Chocolate Waffer - 1.5g - 5.00- Biscuits
8851717200018 - Supreme Seafoods - 65g - 23.00 - Noodles
I wanted my query to provide this kind of result when I query the table of Sold along with Items base on date Sold.Date from 10/14/2011 to 10/16/2011:
Code:
Barcode - Item Name - Size - Units
8851717200014 - Strawberry Yogurt - 90ml - 10
8851717200015 - Chocolate Waffer - 1.5g - 9
8851717200018 - Supreme Seafoods - 65g - 8
-
Oct 14th, 2011, 10:27 AM
#9
Re: [Help] SQL for Datareport Complex Query
Try something like this:
Code:
Select
Items.BarCode ,
Items.Name ,
Items.Size
SUM(Sold.Units)
From
Items
INNER JOIN Sold
ON Items.BarCode = Sold.BarCode
Where Sold.[Date] BETWEEN "Date1# AND #Date2#
(This is a bad field name (DATE) to use by the way as it is a Reserved word)
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 14th, 2011, 10:38 AM
#10
Thread Starter
Member
Re: [Help] SQL for Datareport Complex Query
 Originally Posted by GaryMazzone
Try something like this:
Code:
Select
Items.BarCode ,
Items.Name ,
Items.Size
SUM(Sold.Units)
From
Items
INNER JOIN Sold
ON Items.BarCode = Sold.BarCode
Where Sold.[Date] BETWEEN "Date1# AND #Date2#
(This is a bad field name (DATE) to use by the way as it is a Reserved word)
thanks... i will try it right away... and thanks for the advise about Date being a reserved word... I totally forgot about it... I will surely change it right aways...
-
Oct 14th, 2011, 12:09 PM
#11
Thread Starter
Member
Re: [Help] SQL for Datareport Complex Query
I tried your code but it wont show any result on my DataEnvironment and thus, wont populate the Datareport... this is the actual code I used...
Code:
select Items.ICode, Items.IName, Items.USize, sum(Sold.Units) from Items inner join Sold on Items.ICode = Sold.ICode
I tried this query on Visual Data Manager but all I get is errors...
-
Oct 14th, 2011, 12:11 PM
#12
Re: [Help] SQL for Datareport Complex Query
This was written directly in to the webpage. I do not have your DB so can not test on it. It is just SQL what are the errors?
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 14th, 2011, 01:08 PM
#13
Thread Starter
Member
Re: [Help] SQL for Datareport Complex Query
in dataenvironment... it doest show an error...
-
Oct 14th, 2011, 01:10 PM
#14
Re: [Help] SQL for Datareport Complex Query
Run it in Access then an see what it tells you..... I can't guess as to what is wrong as I can't see your computer screen from here.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 14th, 2011, 02:39 PM
#15
Re: [Help] SQL for Datareport Complex Query
OK Try like this (I missed the Group By clause)
Code:
Select
Items.BarCode ,
Items.Name ,
Items.Size ,
SUM(Sold.Units)
From
Items
INNER JOIN Sold
ON Items.BarCode = Sold.BarCode
Where Sold.[Date] BETWEEN #Date1# AND #Date2#
GROUP BY Items.barcode , items.NAME , items.SIZE
Leave out the Where clause if you don't care about the date range
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 17th, 2011, 08:04 AM
#16
Thread Starter
Member
Re: [Help] SQL for Datareport Complex Query
 Originally Posted by GaryMazzone
OK Try like this (I missed the Group By clause)
Code:
Select
Items.BarCode ,
Items.Name ,
Items.Size ,
SUM(Sold.Units)
From
Items
INNER JOIN Sold
ON Items.BarCode = Sold.BarCode
Where Sold.[Date] BETWEEN #Date1# AND #Date2#
GROUP BY Items.barcode , items.NAME , items.SIZE
Leave out the Where clause if you don't care about the date range
Thanks... It worked...
-
Oct 17th, 2011, 08:08 AM
#17
Re: [Help] SQL for Datareport Complex Query
HP-- If this solves the problem please use the Thread Tools to mark this as Resolved.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 17th, 2011, 10:23 AM
#18
Thread Starter
Member
Re: [Help] SQL for Datareport Complex Query
Another questions...
1. How can I make it that DataEnvironment take date value from a textbox and append it in a query dynamically at runtime?
2. How can I make my datareport dynamically? My "Items" table contain a "Category" column, therefor I made 4 DataEnvironment Command for each category that I have which are "Biscuit", "Beverage", "Noodle" and "New Product".
-
Oct 17th, 2011, 10:42 AM
#19
Re: [Help] SQL for Datareport Complex Query
Don't know for either of these questions. I code everything by hand and don't use the DataEnviorment.
But if you can pass a completed SQL statement to that then I would code the SQL in the code and pass to the DataEnvirronment as shown in my example and also adding a second where condition to include the Category.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 17th, 2011, 07:54 PM
#20
Thread Starter
Member
Re: [Help] SQL for Datareport Complex Query
I also wanted to code all by hand but I do not know how... This is my first time using DataReport... Could you please help me with this? I am not also familiar with ADODC... Only done code in DAO since I started programming...
This is what I Want my report to show:
Barcode Driven Inventory System
Barcode Beverages Size Units
8851717200014 DM Blueberry Yogurt 90mlx48 98
8851717200015 DM Strawberry Yogurt 90mlx48 98
8851717200016 DM Mix Fruit Yogurt 90mlx48 98
8851717200017 DM Blueberry Yogurt 180mlx48 98
8851717200018 DM Strawberry Yogurt 180mlx48 98
8851717200019 DM Mix Fruit Yogurt 180mlx48 98
Barcode Biscuit Size Units
8851717200020 Yummy Wafer 20x20x1.5g 98
8851717200021 Chocolate Wafer 20x20x1.5g 98
8851717200022 Vanilla Wafer 20x20x1.5g 98
8851717200023 Yummy Wafer 20x20x3.5g 98
8851717200024 Chocolate Wafer 20x20x3.5g 98
8851717200025 Vanilla Wafer 20x20x3.5g 98
and so on...
-
Oct 18th, 2011, 07:13 AM
#21
Re: [Help] SQL for Datareport Complex Query
As I said I do not use ADODC or data reports.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 18th, 2011, 11:10 PM
#22
Thread Starter
Member
Re: [Help] SQL for Datareport Complex Query
how do you do it? using DAO?
-
Oct 19th, 2011, 07:20 AM
#23
Re: [Help] SQL for Datareport Complex Query
I use ADODB. Coded directly
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 19th, 2011, 10:37 PM
#24
Thread Starter
Member
Re: [Help] SQL for Datareport Complex Query
can you help me with it... I am not familiar with ADODB...
-
Oct 20th, 2011, 07:24 AM
#25
Re: [Help] SQL for Datareport Complex Query
There are example in the FAQ section of the database area
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Nov 3rd, 2011, 01:25 AM
#26
Thread Starter
Member
Re: [Help] SQL for Datareport Complex Query
I solved my problem on this... thanks to you GaryMazzone....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|