Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Select union with empty rows
Message
De
08/08/2010 15:06:49
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Divers
Thread ID:
01474117
Message ID:
01475671
Vues:
42
>
>Hah? How is it different from what I posted a week ago <B>Re: SQL Select union with empty rows</B> Message #1474131 ?
create cursor curOrder (id i ,iClient i, nAmount n(8,2), iOrderType i )
insert into curOrder values( 1, 1, 100.00, 1)
insert into curOrder values( 2, 2, 110.00, 1)
insert into curOrder values( 3, 2, 120.00, 2)

create cursor curOrdertype (id i, cType c(10))
insert into curOrdertype values(1,"import")
insert into curOrdertype values(2,"export")
insert into curOrdertype values(3,"nmbr3")

create cursor curClient (id i, cName c(10))
insert into curClient values(1,"john")
insert into curClient values(2,"pete")
insert into curClient values(3,"eva")
insert into curClient values(4,"george")

**fabio solution
select curOrdertype.cType;
	, nvl(curOrder.nAmount,0) nAmount;
	, curClient.id iClient;
	, curClient.cName ;
from curClient ;
	join curOrdertype on .t.;
	left join curOrder on curOrder.iOrderType = curOrdertype.id and curClient.id = curOrder.iClient ;
	order by 3,4
browse normal

** solution Sergey
select curOrdertype.cType ;
	, cast(nvl(curOrder.nAmount, 0.00) as n(8,2)) as Amount ;
	, curClient.cName;
from curOrdertype, curClient ;
	left join curOrder on curOrder.iOrderType = curOrdertype.id and curClient.id = curOrder.iClient ;
	order by curClient.id, curOrdertype.id
browse normal
Sergey:
Fabio selects from the table which has all the record (curClient) and joining all the records from the group table (curOrdettype)
with a leftjoin of all the data (curOrder)
i found this a very interesting solution, i was impressed and what is more it works perfectly.

Regards,
Koen
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform