开发者

How do I use `@Count` variable in my query?

开发者 https://www.devze.com 2023-01-30 20:29 出处:网络
I have following SP, I pass a parameter of count to my SP to get specific number of records. But how do I use @Count开发者_如何学运维 variable in my query?

I have following SP, I pass a parameter of count to my SP to get specific number of records.

But how do I use @Count开发者_如何学运维 variable in my query?

CREATE PROCEDURE [dbo].[GetRandomWords1]

    @Count int

AS
BEGIN

    SELECT * From Words

END


Assuming SQL Server 2005+, use TOP:

CREATE PROCEDURE [dbo].[GetRandomWords1]
  @Count int
AS
BEGIN

  SELECT TOP (@Count) * 
    FROM Words

END

TOP is supported on SQL Server 2000, but using the brackets is not -- you have to use dynamic SQL on SQL Server 2000 for equivalent functionality.


Try this:

SELECT TOP(@Count) * From Words ORDER BY NEWID()

Judging from your SP name it seems you want a random words back from your Words table.

0

精彩评论

暂无评论...
验证码 换一张
取 消