Home Forums SQL Server 7,2000 T-SQL Dynamic SQL issues with passing variables in stored procedure RE: Dynamic SQL issues with passing variables in stored procedure

  • Try additional quotes around the variables - two single quote for escape

    EXEC('

    INSERT INTO dbo.ImportError

    (DataElementID, CenterCode, ValueType, ValueDate, [Value], ImportDate, BatchID, ErrorReason)

    SELECT

    DataElementID, CenterCode, ValueType, ValueDate, [Value], GetDate(), ''' + @BatchID + ''', ''' + @ErrorReason + '''

    FROM dbo.ImportAccess

    WHERE' + @WhereStatement)

    ----------------------------------------------------------------------------------------------------------------------------------------------------
    Roshan Joe

    Jeff Moden -Forum Etiquette: How to post data/code on a forum to get the best help[/url]