I have a function...in which I have return type as table variable... But performance will be increased if we use temp tables..as we have more data.
You cannot of course return the temp table. But you can define it in the calling stored procedure. Bear in mind this will only work for stored procedures. You cannot access temporary tables from within functions.
No, you cannot "return" a temp table - you can create that temp table before calling your function, and have your function write data into that temp table.
But this has a tendency to get rather messy .... you need to make sure to have the temp table created before calling the function.....
Have you really, honestly measured the performance of the two approaches?? I don't think temp tables are just always faster.... the approach with the table variable seems a lot cleaner and more intuitive to me.
You can use CLR Table Valued functions that returns the actual table. CLR functions are functions you can write in your native language C#, VB etc. and the dll are embedded in the database.
Learn more about it from here:
this cover just about every way with pros/cons and sample code:
How to Share Data Between Stored Procedures by Erland Sommarskog
Using OUTPUT Parameters
Table-valued Functions
Inline Functions
Multi-statement Functions
Using a Table
Sharing a Temp Table
Process-keyed Table
Global Temp Tables
INSERT-EXEC
Table Parameters and Table Types
Using the CLR
OPENQUERY
Using XML
Using Cursor Variables