Use of SQL Server local variables _mssql

Source: Internet
Author: User
A. Use of DECLARE
The following example uses a local variable named @find to retrieve all the author information that begins with the ring of the last name.
Copy Code code as follows:

Use pubs
DECLARE @find varchar (30)
Set @find = ' ring% '
Select Au_lname,au_fname,phone
From authors
where au_lname like @find


@find is a local variable.

B. Use of two variables in DECLARE
The following example retrieves the name of the employee employed since January 1, 1993 from the employee of Binnet & Hardley (pub_id = 0877).
Copy Code code as follows:

Use pubs
SET NOCOUNT on
Go
DECLARE @pub_id char (4), @hire_date datetime
SET @pub_id = ' 0877 '
SET @hire_date = ' 1/01/93 '
--The SELECT statement syntax to assign values to two local
--variables.
--SELECT @pub_id = ' 0877 ', @hire_date = ' 1/01/93 '
SET NOCOUNT off
SELECT fname, lname
From employee
WHERE pub_id = @pub_id and hire_date >= @hire_date

Here is the result set:

FName lname
-------------------- ------------------------------
Anabela Domingues
Paul Henriot

(2 row (s) affected)
Related Article

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.