Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

TQuery help

Posted on 2007-03-31
11
165 Views
Last Modified: 2013-11-23
I was wondering if anybody could help me with the following:

I have an Access database with tthe following fields:
ID
Date
Time
Album
Artist
Song
MP3
MPG
Filename
Credit
Now what I want is when the person open the form, the following must be displayed in labels according filtered in FromDate to ToDate.

Total MP3
Total MPG
Total Credit MP3
Total Credit MPG
0
Comment
Question by:DigitalNam
  • 6
  • 4
11 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18828308
Hello DigitalNam,

  what is the value of Total MP3 / MPG ?
  also, what is the Total Credit MP3 / MPG ?
  I mean, how are they calculated?
  do you want count(), sum()  and what is the rule to count() / sum() the mp3/mpg ...

Regards,

angelIII
0
 
LVL 6

Expert Comment

by:bokist
ID: 18828319
Hi !

It is not clear, how to find where the credit belongs(mp3 or mpg).
What is the key field for totals(ID ?).

regards,
  steve

0
 
LVL 1

Author Comment

by:DigitalNam
ID: 18828321
Angelll:

When the user plays a mp3 for example, the album song name etc is added to the db with the value of the credit for a mp3 or mpg. So what I want is to give the user a summary of the total credits where field is MP3 of total credits where field is MPG for a certain period.
This is how my db looks at the moment.

ID      Date      Time      Album      Artist      Song      MP3      MPG      FileName      Credit
294      28/03/2007      22:42:02      Anastacia      Anastacia      Welcome to My Truth      Yes      No      07 Welcome to My Truth Anastacia Anastacia Rock 12      1
295      28/03/2007      22:42:13                        No      Yes      Metallica - The Unforgiven II.mpg      5
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18828323
select sum(iif(MP3=Yes,1,0)) TotalMP3
,sum(iif(MPG=Yes,1,0)) TotalMPG
,sum(iif(MP3=Yes,Credit,0)) TotalCreditMP3
,sum(iif(MPG=Yes,Credit,0)) TotalCreditMPG
from yourtable
0
 
LVL 1

Author Comment

by:DigitalNam
ID: 18828333
Angel gives me syntax error (missing operator) in sum(iif(MP3=Yes,1,0)) TotalMP3. How can I get the returned values to display in normal labels?
0
 
LVL 1

Author Comment

by:DigitalNam
ID: 18828336
and how can we base the query on a certain time period? with a calendar dropdown?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18828364
in case the field MP3/MPG are boolean, use True instead of yes.
if its a string field, use 'Yes' instead
possible also, you need to use ; instead of ,   that depends on some regional settings

>How can I get the returned values to display in normal labels?
labels can have a data source also.
ie, make the above query a view (querydef) etc...
0
 
LVL 1

Author Comment

by:DigitalNam
ID: 18828386
Angel, got it wo work, like with the following

select sum(iif(MP3=True,1,0)) AS TotalMP3 , sum(iif(MPG=True,1,0)) AS TotalMPG , sum(iif(MP3=True,Credit,0)) AS TotalCreditMP3 ,sum(iif(MPG=True,Credit,0)) AS TotalCreditMPG from STATS

Seems like the AS was missing. Regarding the label question, I really don't understand your answer. I don't want to display the values returned by the query in a DBgrid, but all in labels.
0
 
LVL 1

Author Comment

by:DigitalNam
ID: 18828397
Ok, I have managed to get the values to TLabel like this

Label22.Caption := 'Total for MPG: ' + IntToStr(DM.Query.Fields[1].AsInteger);

But now how do I get it to show from the 01/01/2007 to 03/01/2007?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 18828406
>But now how do I get it to show from the 01/01/2007 to 03/01/2007?

add that condition in the query:


select sum(iif(MP3=True,1,0)) AS TotalMP3 , sum(iif(MPG=True,1,0)) AS TotalMPG , sum(iif(MP3=True,Credit,0)) AS TotalCreditMP3 ,sum(iif(MPG=True,Credit,0)) AS TotalCreditMPG
from STATS
WHERE [Date] >= #2007/01/01#
AND [Date] < #2007/03/01#
0
 
LVL 1

Author Comment

by:DigitalNam
ID: 18828420
Thanks for the help Angelll... Saved me heaps of time...
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question