Variable
Defining variables: Declare @hello varchar (20)
Assignment: Set @hello = ' Hello '
Select (Results box display)/print (message box display) @hello
* Three rows must be run simultaneously
DECLARE @hello varchar (20)
Set @hello = ' Sales Department '
Select *from bumen WHERE name = @hello
When placed in the middle of select and from, can be used as an assignment statement, do not execute the query function (Assignment is the last row of the query to the data)
DECLARE @hello varchar (20)
Set @hello = ' Sales Department '
Select @hello = name from Bumen
Select @hello
Global variables, System variables
Print @ @connections-value only and cannot be assigned (returns the number of connections to SQL Server since the last startup, whether successful or unsuccessful)
Print @ @error-Returns an error when executing the previous SQL statement, returning 0 for Yes
Print @ @language--Returns the language currently in use
Print @ @rowcount--Returns the number of rows affected by the last operation
Print @ @version--Get version information for the database
Ex.
Update bumen set phone= ' 123 ' WHERE name = ' Sales Department '
Select ' This query statement affects the ' +cast (@ @ROWCOUNT as varchar (10)) + ' line ' altogether
DECLARE @text varchar Set @text = ' ab ' JS ' (single quote when escape word trailing characters)
Print @text
11. SQL Basic Collation (variable)