Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Re: SQL
Divers
Thread ID:
00414860
Message ID:
00414873
Vues:
17
>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
Insanity: Doing the same thing over and over and expecting different results.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform