Results 1 to 5 of 5

Thread: Select TOP @Variable

  1. #1
    Join Date
    Apr 2003
    Posts
    3

    Arrow Select TOP @Variable

    hey,

    how can you make number of returned results from select statement a variable?

    Such as


    declare @variable as int
    select @variable * from Table


    cheers
    vlad

  2. #2
    Join Date
    Sep 2002
    Location
    Montreal
    Posts
    86
    Try this:

    declare @rows int
    set @rows = 5
    set rowcount @rows

    select * from YourTableName

  3. #3
    Join Date
    Sep 2002
    Location
    Montreal
    Posts
    86
    forget one more think:

    make sure after your select statement add a line:

    ...
    ...
    select * from YourTableNmae

    set rowcount 0

  4. #4
    Join Date
    Apr 2003
    Posts
    3
    hi dim,
    thank you for reply,
    i just want to make clear one issue with using set rowcount - does it affect only current session? i mean if there are more connections open at the same time, would it affect others as well?

    cheers
    vlad

  5. #5
    Join Date
    Sep 2002
    Posts
    5,938
    Yes, affect current session only.

Posting Permissions

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