Need to get results of an EXEC(@string_variable) into a local variable

  • Here's one example:

    declare @LockCount int, @WhereClause varchar(1000)

    set @WhereClause = ' Projects.OwnerCode = 25 '

    execute(' select @LockCount = count(*) from DBO.ProjectChangeID join Projects on Projects.ProjectID = ProjectChangeID.ProjectID join OwnerInformation on Projects.OwnerCode = OwnerInformation.OwnerCode where ProjectChangeID.LockFlag > 0 and ' + @WhereClause)

    Resulting Error:  Must declare the scalar variable "@LockCount".

    I have tried variations on this theme, to no avail, (mostly syntax errors.)  There's gotta be a way to do this.  Suggestions?  Thanks in advance,  Joel

    Takauma

  • have a look at *sp_executesql* on BOL.


    * Noel

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

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