Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to return a cursor from sproc?
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01163962
Message ID:
01163975
Views:
9
>
>Table variable is just a local variable declared as table (WOW! what an explanation :-))
>Table variable is kept in memory, temp tables are created in TempDB.
>To declare table variable:
>
>DECLARE @MyTable TABLE (Fld1 Int, Fld2 varchar(50) etc...)
>
>
>Then you could use them as normal table with one condition everywhere you use them in JOIN you must give them alias, something like:
>
>SELECT MyTempTable.*
>       FROM @MyTable MyTempTable
>  LEFT JOIN OtherTable ON ON MyTempTable.PK = OtherTable.Fk
>--- or
>SELECT OtherTable.*
>       FROM OtherTable
>  LEFT JOIN @MyTable MyTempTable ON OtherTable.Pk = MyTempTable.FK
>
>

Thank you very much, Borislav. I guess a table variable is faster to execute than a local temporary table.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform