Search code examples
t-sqlsap-ase

storing a unique value with Top is not posible Sybase


I wonder why i can not do that in sybase 15.5 My table is call "web_titles"

title_id is a varchar(6)

declare @idAux varchar(6)
set @idAux  = (select top 1 title_id from web_titles)

if i just do

select top 1 title_id from web_titles

return

title_id
-----------
PC8888

but if i try to set the variable i recive

Sybase error

"Incorrect syntax near the keyword 'top' "

I dont understand why. Any idee?


Solution

  • To assign value to variable you could use:

    declare @idAux varchar(6);
    select top 1 @idAux = title_id from web_titles;
    

    Keep in mind that TOP 1 without ORDER BY is not reliable.