Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
UNION SELECT... please correct me
Message
De
27/10/1998 07:20:18
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
27/10/1998 05:25:06
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00150818
Message ID:
00150836
Vues:
15
>Hi
>I want to receive 2 records from the table between which the variable is located.
>
>My code:
>SELECT TOP 1 * ;
>FROM myDatabase!myTable ;
> WHERE myTable.cod = pCod ;
> AND myTable.price >=pPrice ;
> UNION ;
> SELECT TOP 1 *;
> FROM myDatabase!myTable;
> WHERE myTable.cod = pCod ;
> AND myTable.price <=pPrice ;
>ORDER BY mytable.price ;
>INTO CURSOR curPrice
>
>I receive error message... What the problem ?... OR I do't use TOP 1 AND UNION ?
>Thanks for your messages.
>Denis.
Denis,
Top n requires "order by" and you can't use two "order by" for a union. Unfortunately you should divide it into 3 SQLs (if ever there is a better way I don't know it).
SELECT TOP 1 * ;
  FROM myDatabase!myTable ;
  WHERE myTable.cod = pCod ;
  AND myTable.price >=pPrice ;
  into cursor crsPass1 ;
ORDER BY mytable.price

SELECT TOP 1 * ;
  FROM myDatabase!myTable ;
  WHERE myTable.cod = pCod ;
  AND myTable.price <=pPrice ;
  into cursor crsPass2 ;
ORDER BY mytable.price DESC

select * from ;
  crsPass1 ;
  UNION ;
  select * from crsPass2 ;
INTO CURSOR curPrice
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform