开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜