Total Pageviews

PRINT in SQL Server



  • Returns a user-defined message to the client. 
  • Message should have string ((n)varchar) data type.
  • If we are planning to PRINT any variable value and that variable is not of string data type then only after converting it to string data type, we can print that.
  • A message string can be up to 8,000 characters long if it is a non-Unicode string, and 4,000 characters long if it is a Unicode string.
  • Print also help us in debugging.
For example:-

a) PRINT a user defined message :-



b) PRINT Variable value having string data type:-



c) PRINT variable value not having string data type:-










 

TOP n PERCENT

TOP n [PERCENT]

With the help of this we can limit the result set.

In the case of TOP, by default it will return the n number of rows of total result set but if we use PERCENT with TOP then it will return the n PERCENT record of total result set.

PERCENT is optional with TOP.

For example:-