• Hi all,

    I rewrite to another one.

    Create proc ExtractDataforProducer (@StartDate Datetime, @EndDate Datetime, @SubProducerFlag char(1), @TableName varchar(15), @AgentCode varchar(10))

    As

    Select * from @TableName tn

    inner join tis_vs vs on tn.pnref=vs.pnref

    and agentCode

    Case When @SubProducerFlag='Y'

    Then like End,

    Case When @SubProducerFlag !='Y'

    Then = End

    @AgentCode

    and convert(char(10), vs.txndatetime,126) between convert(char(10),@StartDate,126) and convert(char(10), @EndDate, 126)

    order by vs.txndatetime

    But I still get an error message:

    Msg 1087, Level 15, State 2, Procedure ExtractDataforProducer, Line 3

    Must declare the table variable "@TableName".

    Maybe the table cannot be variable here?