Cari Blog Ini

20 April 2012

Table Variables

If you are using SQL Server 2000 or higher, you can take advantage of the new TABLE variable type.
These are similar to temporary tables except with more flexibility  and they always stay in memory. 
Table variables don't need to be dropped when you are done with them.

The code above using a table variable might look like this:

-----start-----
DECLARE @Test_Table_Variables TABLE
(
    Table_Var_ID int,
    Table_Var_Name char(30)
)

INSERT INTO @Test_Table_Variables (Table_Var_ID, Table_Var_Name)
SELECT     KdSubDept, Bagian
FROM     dbo.Bagian
WHERE     KdDept = '01'

SELECT * FROM @Test_Table_Variables

UPDATE     @Test_Table_Variables
SET     Table_Var_Name = LOWER(Table_Var_Name)

SELECT * FROM @Test_Table_Variables
-----end-----