We are migrating a db from Sybase SQLAny to SS2K5. One SQLAny developer used the the following technique integrate a "WhereClause" string parameter into a procedure cursor. Here's the gist:
CREATE PROCEDURE DBO.CancelProcess @WhereClause varchar(max) as....
declare @Select1 varchar(max)
set @Select1=' SELECT Projects.ProjectID, Projects.TargetStartDate, Projects.TargetFinishDate, Projects.StatusCode
from dbo.Projects WHERE ' + @WhereClause
begin
declare curCancel insensitive scroll cursor for @Select1
.....
The error we get is:
Incorrect syntax near '@Select1'
I've tried a few techniques that I know, like declaring the cursor in a Execute statement:
set @Select1= 'SET @curCancel = CURSOR scroll FOR SELECT Projects.ProjectID, Projects.TargetStartDate from DBO.Projects WHERE ' + @WhereClause ;
Execute @Select1
I'm not getting anywhere. What am I missing?