11. SQL Basic Collation (variable)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.