Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004

    Unanswered: TOP clause Query ?

    Hi all,

    In Oracle 'ROWNUM' can be used with any variables.

    eg : select sno from test1 where rownum < variable1 ( say variable1 is a local variable )

    Is there any equivalent for the above in SQL Server ?

    Hint :

    If 'select sno from test where rownum < 10' in Oracle, then SQL Server equivalent is 'select top 9 sno from test'.

    The same way I need the equivalent for the above.


  2. #2
    Join Date
    Feb 2004
    usually select top [num] ... does the trick, but it accepts no variables. I think a dynamic query is required, fe:
    declare @myint as integer
    declare @myvar as varchar(30)
    set @myint = 10
    set @myvar = 'select top ' + convert(varchar, @myint) + ' * from table1'
    print @myvar
    exec (@myvar)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts