Declaring cursor using contacented strings (user define where clause)

  •  

    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?

    Takauma

  • Cone on out there!  Surely there's a way to pass a whereclause into a cursor declaration!

    Takauma

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply