Alias for a table that can be used for the duration of a procedure?

  • I'm not sure if this can be done, but is there a way to use a table alias for the duration of a stored proc, including sub procedures?

    For example if you wanted to have an alias Customers that could refer to either the DailyCustomers table or the MonthlyCustomers table, perhaps set by a flag? Pre-empting the obvious point that a Customers could contain both with a flag set - in this case there are very good reasons (due to data feeds basically) that this is not possible here and cannot be used in this case, which I don't want to go into here 😉

    I think I'm right in saying a CTE wouldn't have scope in sub procedures?

    Thanks in advance.

  • You are right in suggesting that a CTE won't work in this case.

    You might want to try experimenting with SYNONYMs. Aliases are limited in scope to the query in which they are defined.

    Have a look here, for example.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Thanks Phil, perfect, I knew there was something but couldn't remember the name, not having used it before 😊

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

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