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.
精彩评论