Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with LEFT JOIN
Message
 
 
To
20/01/2005 10:28:45
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
00978845
Message ID:
00978889
Views:
34
>The parenthesis are to keep its order of operations straight. You do need to be careful with them and OR conditions to be sure you receive the correct results.
>When I have optional parameters, they're usually to filter the result set, so not sending that parameter would have no effect. The WHERE clause in that case looks like IIF(EMPTY(?vp_optional, .T., table.optional = ?vp_optional). I don't use NULLs, but you should be able to adapt that for them.
>
>Chris.

Hi Chris,

Are you able to put it in the View Designer? Could you please post one of your views using this technique so I may try to adopt it for my needs?

Right now I'm playing with my original idea from the program. I was unable to save this view in View Editor.

It worked from the program, so I may try to put it in the view editor now.
vp_cClient_Account_Number = "%"
vp_cLast = "%"
vp_cFirstName = "%"
vp_cMiddle = "%"
vp_cSSN = "%"
vp_cAreaCode = "%"
vp_cExchange = space(0)
vp_cFour = space(0)
vp_cExchange_Four = "643%"
 
SELECT MIN(Trans.ctrans_pk) AS ctrans_pk, ;
		Trans.cclient_account_number, ;
		MIN(Patients.ddob) AS ddob, ;
		MIN(Trans.tadmit_date) AS dos, ;
		MIN(PADR(NVL(ALLTRIM(Names.cl_name)+", ", "")+NVL(ALLTRIM(Names.cf_name)+" ", "")+NVL(Names.cm_initial, ""), 50)) AS cpatient_name, ;
		MIN(Product_lines.cproduct_line) AS cproduct_line, ;
		MIN(Trans.cresolution_codes_fk) AS cresolution_codes_fk, ;
		MIN(Trans_status_codes.cstatus_codes_fk) AS cstatus_codes_fk, ;
		MIN(PADR(NVL(Phones.carea_code, "")+NVL(Phones.cexchange, "")+NVL(Phones.clast_four, ""), 10)) AS cphone ;
	FROM mmviscollect!patients INNER ;
		JOIN mmviscollect!trans ;
				ON Patients.cpatients_pk = Trans.cpatients_fk ;
		LEFT JOIN mmviscollect!phones ;
				ON Patients.cpatients_pk = Phones.cpointer_fk INNER ;
		JOIN mmviscollect!trans_status_codes ;
				ON Trans.ctrans_pk = Trans_status_codes.ctrans_fk INNER ;
		JOIN mmviscollect!product_lines ;
				ON Product_lines.cproduct_lines_pk = Trans.cproduct_lines_fk INNER ;
		JOIN mmviscollect!names ;
				ON Patients.cpatients_pk = Names.cpointer_fk ;
	WHERE Trans.cclient_account_number LIKE ( ?vp_cClient_Account_Number ) ;
		AND Trans_status_codes.iactive_flag = ( 1 ) ;
		AND Names.cl_name LIKE ( ?vp_cLast ) ;
		AND Names.cf_name LIKE ( ?vp_cFirstName ) ;
		AND Names.cm_initial LIKE ( ?vp_cMiddle ) ;
		AND Patients.cssn LIKE ( ?vp_cSSN ) ;
		AND (Phones.carea_code LIKE ( ?vp_cAreaCode ) ;
		OR (m.vp_cAreaCode = "%" AND Phones.carea_code IS NULL)) ;
		AND (( Phones.cexchange+Phones.clast_four ) LIKE ( ?vp_cExchange_Four ) ;
		OR (m.vp_cExchange_Four = "%" AND ( Phones.cexchange+Phones.clast_four ) IS NULL)) ;
	GROUP BY Trans.cclient_account_number
Thanks a lot in advance.

UPDATE. I managed to get it to work, but vp_cAreaCode and vp_cExchange_Four should exist prior to accessing this view. I'm afraid, I may have problems down the road...
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform