C# SQL Top as parameter
You need to have at least SQL Server 2005. This code works fine in 2005/8 for example ...
DECLARE @iNum INTSET @iNum = 10SELECT TOP (@iNum) TableColumnIDFROM TableName
If you have SQL Server 2000, give this a try ...
CREATE PROCEDURE TopNRecords@intTop INTEGERASSET ROWCOUNT @intTopSELECT * FROM SomeTableSET ROWCOUNT 0GO
You could write an inline query:
EXEC 'SELECT TOP ' + @topparam + ' * FROM ... '
Parse it as an int and that will prevent a SQL injection attack.