What is the use of declare and print in the T-SQL language?

Source: Internet
Author: User
-- Declare
Declare a variable using the declare statement in the body of a batch or process and assign a value to it using the set or select statement. The cursor variable can be declared through this statement and can be used in other statements related to the cursor. All variables are initialized to null after declaration.

-- Print

The print statement uses a single character or Unicode string expression as a parameter. It returns this string as a message to the application. The message is returned as a message error in ADO, ole db, and ODBC applications. Sqlstate is set to 01000, the local error is set to 0, and the error message string is set to the string specified in the print statement. The string is returned to the message handler callback function of the DB-library application.

The print statement accepts any string expression, including a character or Unicode constant, character or Unicode local variable name, or a function that returns a character or Unicode string. In Microsoft & reg; SQL Server & Trade 2000, print also accepts complex strings generated by concatenating two or more constants, local variables, or functions.

Print helps us discover and solve problems in the transact-SQL code, check data values, or generate reports.

TIPS:
This page (http://www.cnblogs.com/qiantuwuliang/archive/2009/07/19/1526408.html) when the instance used print, can play a "Debug SQL" role !!!

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.