Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL
Message
De
11/09/2000 10:37:44
Cindy Winegarden
Duke University Medical Center
Durham, Caroline du Nord, États-Unis
 
 
À
11/09/2000 10:20:00
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Re: SQL
Divers
Thread ID:
00414860
Message ID:
00414888
Vues:
27
There won't be any NULLs without a LEFT JOIN. Otherwise it will only return those that have a matching record in the Orders table.
SELECT ;
    Orders.Id, ;
    NVL(Clients.ClientName, PADR("Sir/Madam", nn)) AS ClientName ;
    FROM Orders LEFT JOIN Clients ON Orders.Id = Clients.Order_id;
    INTO CURSOR Temp ;
    ORDER BY.....


>>HELLO,
>> What did I do wrong in the following statement it returns no record:
>> select orders.id, iif(isnull
>> (clients.name), "Sir/Madam",clients.name) as name ;
>> from orders,clients ;
>> where orders.id == clients.order_id ;
>> into cursor temp
>>what I am trying to do is if the order has a contact name I will print out the name otherwise just say "sir/madam". thanks.
>>sherry
>
>Looks OK to me - the only thing that should cause it to return no records is if
>the WHERE clause found no matches.
>I would suggest a couple of changes, though:
>1) name and id are VFP keywords - if possible, you should rename these to use fields that are not VFP keywords.
>2) Use NVL() instead of ISNULL()- it's a little faster
>3) PADR() the "Sir/Madam" the size of the name field because if the length of the client name field if more thn 9 (LEN("Sir/Madam"), the remaining records will have a length of 9 as well, so they will be truncated.
>
>So, with these suggestions, the select would look like this
>
select orders.orders_id, ;
>  NVL(clients.client_name, PADR("Sir/Madam",FSIZE("client_name","clients"))) As client_name ;
>  from orders, clients ;
>  where orders.order_id == clients.order_id ;
>  into cursor temp
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform