Link to home
Start Free TrialLog in
Avatar of davidtotty
davidtotty

asked on

SQL Select Statement Question.

I use an SQL Select statement to gather data from three tables and combine it into one for use as statements. The problem is people aren't doing their job properly and are creating invoices before the job has been moved into one of the tables in the statement. I am using an Inner Join but the problem is if the value is in one table and not in the other it skips the record. Accounts are complaining because invoices are in the accounts system but not showing up on the statement.

I need to have some sort of error or flag show up when a record meets the criteria but isn't found in both tables. What is the best way to go about this?

The code i am using is below. What am i doing wrong?  


	SELECT S_STRAN.ST_ACCOUNT, S_STRAN.ST_TRDATE, S_STRAN.ST_TRTYPE,;
		S_STRAN.ST_TRREF, INVOICE.MARKNUM1, S_AOIM01.M_REQNUM, S_STRAN.ST_FCVAL;
		FROM ;
		COMP_S!STRAN S_STRAN ;
		INNER JOIN  K:\NCOST\INVOICE.DBF ;
		INNER JOIN "K:\SSS\S-AOIM01.DBF" S_AOIM01 ;
		ON  INVOICE.MARKNUM1 = S_AOIM01.M_PONUM ;
		ON  S_STRAN.ST_TRREF = INVOICE.INV_NUM;
		WHERE  S_STRAN.ST_ACCOUNT = "ZUE002";
		AND S_STRAN.ST_TRDATE >= STARTDATE AND S_STRAN.ST_TRDATE <=ENDDATE;
		ORDER BY S_STRAN.ST_TRREF;
		INTO TABLE K:\TRANSDATA\EXCEL\STDATA\XYSTDATAT.DBF

Open in new window


Thanks
SOLUTION
Avatar of Olaf Doschke
Olaf Doschke
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of davidtotty
davidtotty

ASKER

Thanks for all your help guys. It's given me a lot to think about.

Going to change some of the other processes in the system so people can't "move the goalposts" and use your recommendations.

David
Thanks for all your help