Local variable local variables must begin with @ and must be described with the DECLARE command before they can be used. Use the Select or SET command to set the value of the variable. Description form:
DECLARE @ variable name variable type [@ variable name variable type]
SELECT @ local variable = variable value
SET @ local variable = variable value IF ... ELSE ...
IF < conditional expressions >
< command line or program block >
[ELSE IF [conditional expression]
< command line or program block;] BEGIN ... END ...
BEGIN
< command line or program block >
END BEGIN ... END is used to set a program block that will be at begin ... All programs in END are treated as one unit execution. BEGIN ... END often in conditional statements such as if ... ELSE used in. The WAITFOR WAITFOR command is used to temporarily stop the execution of the program until the waiting time has been set or the time has been set to continue. Where time must be a datetime type of data
WAITFOR {Delay < ' time ' > | Times < ' time ' >| Errorexit | ProcessExit | Mirrorexit} delay is used to set the wait time up to 24 hourstime is used to set the point at which the wait endsErrorexit until a non-normal interrupt is handledProcessExit until normal or non-normal interrupts are handledMirrorexit until the mirror device failsExample: wait 1 hours, 2 minutes, 3 seconds before executing the SELECT statement
waitfor delay ' 01:02:03 ' SELECT * FROM Employee The SELECT statement is not executed until 11 o'clock 8 minutes after the night
waitfor time ' 23:08:00 ' SELECT * FROM Employee
140911 SQL Programming