Avatar of Mark

asked on 

how to delete a variable number of rows?

I have a stored procedure and want to delete a number of rows than can vary:

declare @rowsToDelete int
set @rowsToDelete = 20

delete top @rowsToDelete from @myTable where someColumn = 'this' order by someOtherCol asc

This doesn't work. I get: "Select Failed: 102 Incorrect syntax near '@rowsToDelete'.

Is there a way?
Microsoft SQL Server 2005

Avatar of undefined
Last Comment

8/22/2022 - Mon