Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Trouble getting result from join query
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows 7
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01545667
Message ID:
01545701
Views:
42
>Try
>
>SELECT count( DISTINCT person.lname), ;
>	sum(pinfo.workhour)
>	FROM Person INNER JOIN Pinfo ON person.personid = pinfo.personid ;
>	WHERE person.personid IN (1,2) ;
>
Hi Naomi, long time no talk. I tried the sample above and it gave me result for only one person (The first person work hours from pinfo actually). Also can the where clause be expanded further to include more filtering, When I added more items to WHERE clause, I got zero results:
SELECT count( DISTINCT person.lname), 	sum(pinfo.workhour) ;
	FROM Person INNER JOIN Pinfo ON person.personid = pinfo.personid ;
	WHERE person.personid IN (1,2) AND Person.personid = 3054 ;
and person.personid = 3151
In reality, what I am trying to do is combine 2 queries into one.

here is query1 getting count
SELECT COUNT(Person.fname);		
FROM  workprog!person ;
 WHERE Person.startdate >= .txtFromdate.value;
   AND Person.startdate <= .txtTodate.value;
   AND upper(Person.court) = "R";
   AND upper(Person.sex) = 'M' ;
   OR (Person.startdate >= .txtFromdate.value;
   AND Person.startdate <= .txtTodate.value;
   AND upper(Person.court) = "J") ;
   AND upper(Person.sex) = 'M' ; 
into cursor personcount 
here is query 2 getting sum from child record
SELECT sum(Pinfo.workhour) AS WorkhourSum;	
 FROM  workprog!person inner join workprog!pinfo ON person.personid = pinfo.personid;
 WHERE Person.startdate >= .txtFromdate.value;
   AND Person.startdate <= .txtTodate.value;
   AND upper(Person.court) = "R";
   AND upper(Person.sex) = 'M' ;
   OR (Person.startdate >= .txtFromdate.value;
   AND Person.startdate <= .txtTodate.value;
   AND upper(Person.court) = "J") ;
   AND upper(Person.sex) = 'M' ;   
   into cursor wrksum
I want to combine these two queries so that the results will show the number of people from person table (COUNT(Person.fname) and sum(Pinfo.workhour) AS WorkhourSum. This is probably not doable, but I thought I would consult with the foremost experts on UT. Thanks for your assist Naomi.

Nick
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform