Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 sql top

Author  Topic 

casati74
Posting Yak Master

109 Posts

Posted - 2006-09-11 : 03:52:27
hello,
it's possible in a select top 10 instruction replace 10 with a @variter???


es:

select top @variter
from my table?????

thank's

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-09-11 : 03:54:12
in sql server 2005 use
select top(@variter) ...

in sql server 2000 use
set rowcount @variter
select ...
set rowcount 0




Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-11 : 03:54:44
SET ROWCOUNT @Variter

select * from mytable

SET ROWCOUNT 0

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-11 : 07:39:31
It hurts to be me.



Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-11 : 11:45:44
In sql server 2000, Top @variter is possible only by Dynamic SQL

Exec('Select top '+cast(@variter as varchar(10))+' cols from table')

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -