March 3, 2009 at 12:00 pm
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.....
March 3, 2009 at 12:16 pm
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?
March 3, 2009 at 12:57 pm
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??
March 3, 2009 at 2:53 pm
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?
March 4, 2009 at 10:43 am
Thank you...
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply