select top query
-
In you are using SQL Server 2000 then this is not possible.
Recent blog posts: * Introduction to LINQ to XML (Part 1) - (Part 2) - (part 3) My website | Blog
-
-
in sql server 2000 try create procedure ss(@s int) as SET ROWCOUNT @s select sno from summa1 order by newid SET ROWCOUNT 0 ROWCOUNT should turn pink..i havnt used it in a while so i may have typed it wrong. I do not believe that Rowcount is available in sql server 2k5, it was replaced with something but i dont remember what. EDIT: ROWCOUNT is the correct one..@@ROWCOUNT wont work. you could also use dynamic sql like EXEC 'SELECT TOP ' + CAST(@s AS CHAR) + ' sno FROM summa1 ORDER BY newid'
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
modified on Friday, June 27, 2008 4:16 PM
-
In you are using SQL Server 2000 then this is not possible.
Recent blog posts: * Introduction to LINQ to XML (Part 1) - (Part 2) - (part 3) My website | Blog
-
in sql server 2000 try create procedure ss(@s int) as SET ROWCOUNT @s select sno from summa1 order by newid SET ROWCOUNT 0 ROWCOUNT should turn pink..i havnt used it in a while so i may have typed it wrong. I do not believe that Rowcount is available in sql server 2k5, it was replaced with something but i dont remember what. EDIT: ROWCOUNT is the correct one..@@ROWCOUNT wont work. you could also use dynamic sql like EXEC 'SELECT TOP ' + CAST(@s AS CHAR) + ' sno FROM summa1 ORDER BY newid'
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
modified on Friday, June 27, 2008 4:16 PM
I don't think this would work, I'm pretty sure @@rowcount is read only. I don't have sql server 2000 installed, but I have never seen @@rowcount being set, only ever read. What I think is meant is set rowcount, but this cannot be set to a parameter, so you are back to dynamic sql
SomeGuyThatIsMe wrote:
I do not believe that Rowcount is available in sql server 2k5,
Both rowcount (to set the number of rows returned) and @@rowcount (the number of rows affected) are both still alive and kicking in SQL Server 2005
Bob Ashfield Consultants Ltd
-
I don't think this would work, I'm pretty sure @@rowcount is read only. I don't have sql server 2000 installed, but I have never seen @@rowcount being set, only ever read. What I think is meant is set rowcount, but this cannot be set to a parameter, so you are back to dynamic sql
SomeGuyThatIsMe wrote:
I do not believe that Rowcount is available in sql server 2k5,
Both rowcount (to set the number of rows returned) and @@rowcount (the number of rows affected) are both still alive and kicking in SQL Server 2005
Bob Ashfield Consultants Ltd
It works fine i have it done in multiple places mostly in stored procedures, and in some other queries. SET ROWCOUNT it works well for randomizing the data you pull from a table with no PK. @@ROWCOUNT might be read only, ROWCOUNT is the correct one to use.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
It works fine i have it done in multiple places mostly in stored procedures, and in some other queries. SET ROWCOUNT it works well for randomizing the data you pull from a table with no PK. @@ROWCOUNT might be read only, ROWCOUNT is the correct one to use.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
SomeGuyThatIsMe wrote:
You can use SET @@rowcount or
I'm pretty sure you're thinking of
SET ROWCOUNT
and notSET @@ROWCOUNT
.@@ROWCOUNT
tells you how many rows were affected by a statement.Deja View - the feeling that you've seen this post before.
-
It works fine i have it done in multiple places mostly in stored procedures, and in some other queries. SET ROWCOUNT it works well for randomizing the data you pull from a table with no PK. @@ROWCOUNT might be read only, ROWCOUNT is the correct one to use.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
Although be aware that as far as I know, ROWCOUNT is being deprecated in 2K5 and it is removed from SQL Server 2K8 (or perhaps the one after 2K8)
--------------------------- Blogging about SQL, Technology and many other things
-
Although be aware that as far as I know, ROWCOUNT is being deprecated in 2K5 and it is removed from SQL Server 2K8 (or perhaps the one after 2K8)
--------------------------- Blogging about SQL, Technology and many other things
yep thats what i read...they are replacing it with something, but i dont think it works quite the same.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.