Archive

Archive for the ‘Operators’ Category

Rank function in transact SQL

February 8th, 2012 admin No comments

Rank() function is used to give ranking to the records chosen through a select clause.  Rank function is very commonly used in the industry for many purposes.

The general syntax of rank function is

RANK ( )  OVER ( [  partition by < column_list > ]  order by  <column_list> )

The PARTITION BY clause divides the result set produced by the FROM clause into separate partitions. Rank is applied to each of these partion.

The ORDER BY  clause determines the order in which the RANK values are applied to the records in a partition.

Read more…

Understanding RAISERROR statement in SQL server

November 18th, 2010 admin No comments

RAISERROR statement is used to return error messages to the business applications that executes SQL statements. The usual errors returned by the SQL server may not make much sense to the business applications users hence we overwrite it by using RAISERROR to display meaningful messages. The statement uses same format as a system error or warning messages generated by SQL server.

You can return a user-defined error message by using RAISERROR.  The general syntax is as below

RAISERROR ( { msg_id | msg_str | @local_variable }

    { ,severity ,state }

    [ ,argument [ ,...n ] ] )

    [ WITH option [ ,...n ] ]

 

ExamplesRAISERROR (‘Error raised in TRY block.’, — Message text.

Read more…

Understanding logical operators ( And / Or / Not ) in SQL Server

November 14th, 2010 admin No comments

Logical operators can be used in the queries to retrieve records based on one more conditions. In a select statement, the conditions specified by the logical operators are connected using a WHERE clause.

General syntax :

Select ColumnList

From TableName

Where ConditionalExpr1 {AND/OR} [NOT]   ConditionalExpr2

There are 3 types of logical operators

Read more…