SET @local_variable

Set a local variable, previously created with Declare

Syntax
      SET @local_variable [:: property | field ]
         = expression | udt_name { . | :: } method (argument [ ,...n ] ) 

      SET @cursor_variable = @cursor_variable | cursor 

      SET @cursor_variable =  CURSOR [ FORWARD_ONLY | SCROLL ] 
         [STATIC | KEYSET | DYNAMIC | FAST_FORWARD ] 
            [READ_ONLY | SCROLL_LOCKS | OPTIMISTIC ]  [TYPE_WARNING ] 
               FOR select_statement 
                  [FOR { READ ONLY | UPDATE [ OF column [ ,...n ] ] } ]  
 

Key
   property     Property of a user-defined type.
   field        Public field of a user-defined type.
   udt_name     Name of a Common Language Runtime user-defined type.
   {. | ::}     A method (static :: or non-static .) of a CLR user-define type.
   method       A method of a user-defined type, the arguments modify its state.
   CURSOR       Cursor declaration.
   SCROLL       Allow all cursor fetch options: FIRST, LAST, NEXT, PRIOR, RELATIVE, ABSOLUTE.
   FAST_FORWARD A FORWARD_ONLY, READ_ONLY cursor with optimizations enabled.
   FORWARD_ONLY Only allow FETCH NEXT.
   STATIC       Non-updatable cursor, uses a temporary table in tempdb.
   KEYSET       Fix the membership and order of rows in the cursor.
   DYNAMIC      Reflect all data changes made to the rows.
   SCROLL_LOCKS Lock the rows as they are read into the cursor.
   OPTIMISTIC   Do not lock rows as they are read into the cursor.
   TYPE_WARNING Send a warning message if the cursor is implicitly converted.
   FOR          A SELECT statement to define the cursor result set.
   UPDATE       Define updatable columns within the cursor. default=all cols.

In SQL Server 2005, both FAST_FORWARD and FORWARD_ONLY cursor options can be used in the same DECLARE CURSOR statement.

Example

DECLARE @myvar char(20);
SET @myvar = 'Hello World';
SELECT @myvar;
GO

"Come on baby, light my fire, Try to set the night on fire" ~ The Doors

Related commands:

DECLARE
EXECUTE
SELECT
SET


© Copyright SS64.com 1999-2014
Some rights reserved