What I’m trying to do from this query is i’m trying to get all the rows which are older than the specified Cutoffnumber from customertransaction table:
@Cutoffnumber INT
SELECT @SQL = 'SELECT * FROM customertransaction WHERE DATEDIFF(DD, Transactiondate, GETDATE()) > @Cutoffnumber '
But i’m getting the below error, Note that this is a dynamic SQL query.
Must declare the scalar variable “@Cutoffnumber”
How should I go about.
Look into sp_executesql