• Getting an error:

    declare @TableName varchar(100)

    ,@SQL1 varchar(2000)

    ,@SQL2 varchar(2000)

    ,@SQL3 varchar(2000)

    ,@SQL4 varchar(2000)

    ,@SQL5 varchar(2000)

    ,@SQL6 varchar(2000)

    ,@Parameters int

    ,@TypeOfCrud int--1 = Insert, 2 = Update, 3 = Read, 4 = Delete, 5 = All

    select @TableName = 'CUSTOMER_ORDER' --<<Enter the name of the table

    ,@Parameters = 0 --<< If using parameters for the insert statement then use 1 if not then use 0

    ,@TypeOfCrud = 3

    As you can see, I chose a table from my database, "read" type, and get I get this error at the exec(@SQL1) statement and exec(@SQL@) statements:

    Msg 197, Level 15, State 1, Line 235

    EXECUTE cannot be used as a source when inserting into a table variable.

    Msg 197, Level 15, State 1, Line 241

    EXECUTE cannot be used as a source when inserting into a table variable.

    if isnull(@SQL1, '') ''

    begin

    insert into @FinalSelect([--SelectText])

    exec (@SQL1)

    if isnull(@SQL2, '') ''

    begin

    insert into @FinalSelect([--SelectText])

    exec(@SQL2)

    end