Table Valued User Functions??

  • Help....I'm trying to use a Table function and I need to know if you can use the input variable in the From Clause instead of the Where clause? I have a table name that changes every month and I want to use the table name as my variable.....

  • Essentially - no. Not in a function.

    In order to do that you would need to run the statement as "dynamic SQL" which is not possible through T-SQL functions (since EXEC statements and/or invoking sp_executeSQL is not allowed).

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • If I use dynamic SQL, can I pull results out of that to be used later in the stored procedure? The ultimate goal is to pass in the variable as the table name and pull out a set of unique dates in the table.

    Oh snap...why can't anything be easy??

  • If you want to reuse them - then dump them into a temp table. Just create the temp table in the calling stored proc, fill it using the dynamic SQL, and then use it.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Thank you...

Viewing 5 posts - 1 through 4 (of 4 total)

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