Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Functions - Variable Table / Temp Tables

Author  Topic 

sqldba20
Posting Yak Master

183 Posts

Posted - 2008-11-25 : 09:56:54
Folks:

I have a query which combines 2 temp tables. I ran the query with # tables and the query finishes (returns results) in less than 25 secs. The problem is I want to use this query as tvf (function) and I cannot use # tables in functions so I use the variable tables and then it takes 2 mins to complete the process. What are my options?



Thanks!

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-25 : 10:11:43
Hard to guess without seeing what your code is doing.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-25 : 12:17:50
quote:
Originally posted by sqldba20

Folks:

I have a query which combines 2 temp tables. I ran the query with # tables and the query finishes (returns results) in less than 25 secs. The problem is I want to use this query as tvf (function) and I cannot use # tables in functions so I use the variable tables and then it takes 2 mins to complete the process. What are my options?



Thanks!


Try if you can rewrite code as inline table function. type 2 in below link

http://www.sqlteam.com/article/user-defined-functions
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2008-11-25 : 13:01:42
Instead of using temp tables in your function, use Common Table Expressions.

If it is not practically useful, then it is practically useless.
Go to Top of Page
   

- Advertisement -