>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