Solved

TQuery help

Posted on 2007-03-31
11
155 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 142

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
 
LVL 142

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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 142

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 142

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
System restore point 4 79
Copy file in dll not working but working on exe ! 18 83
Delphi XE10, MySQL Query 4 109
Help on project with Soap 10 44
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now