Total Touch

A leading international company ever

ASP Knowledge Center cliniquementchill.com

Transact-SQL (T-SQL) - expanding language SQL companies Microsoft (for Microsoft SQL Server) and Sybase (for Adaptive Server Enterprise). T-SQL could be used for ASP MS Access & ASP access table web applications.

In order to make the language more powerful, SQL has been expanded with additional capabilities such as:

     * Administering operators
     * Local variables
     * Various additional functions (for processing lines, dates, math, etc.)
     * Support for Microsoft Windows authentication

Managers operators

To control the flow of execution in Transact-SQL, the following operators: BEGIN and END, BREAK, CONTINUE, GOTO, IF and ELSE, RETURN, WAITFOR and WHILE.

The local variables

For ads local variable given type the keyword DECLARE. In declaring all variables initialized value NULL. To assign a variable value, you should use the keyword SET.

The next script declares a variable type, it sets the value and performs the cycle of using it as an enumerator.

DECLARE @ Counter INT
SET @ Counter = 10
WHILE @ Counter> 0
BEGIN
    PRINT 'The count is' + CONVERT (VARCHAR (10), @ Counter)
    SET @ Counter = @ Counter - 1
END


Also variable can be initialized result query:

DECLARE @ UserName NVARCHAR (100)
SELECT @ UserName = UserName FROM Users


After the execution of this script the variable @ UserName the value relevant field last selected records. If the request does not return any entry, the variable, unlike the operator SET, will not change.

Global

SQL Server has a number of predefined global variables (global variables), which are designed to obtain information on the status of the server, database or current connection. Unlike local variables their importance can not be changed. Name of global variables begins with two characters "@".

Examples of global variables:

     * @ @ ERROR - returns an error number of last execution
     * @ @ ROWCOUNT - returns the number of rows processed last team (SELECT, INSERT, DELETE, UPDATE)
     * @ @ SERVERNAME - name server
     * @ @ VERSION - version of SQL Server


Correlatives variables

Correlatives variables (table variables) appeared in 2000 - a version of SQL Server. Designed for temporary storage of data sets for further processing. By table variables can be applied standard commands SQL (SELECT, INSERT, DELETE, UPDATE).

For example

DECLARE @ UserNames TABLE
(
   LastName VARCHAR (50) NOT NULL,
   FirstName VARCHAR (50) NOT NULL,
   BirthDay DATETIME
)
 
INSERT INTO @ UserNames (LastName, FirstName, BirthDay)
VALUES ( 'Ivanov', 'Ivan','1977-04-27 ')
 
INSERT INTO @ UserNames (LastName, FirstName)
VALUES ( 'P.', 'Peter')


This snippet announces table variable @ UserNames and inserts it in two entries.