Showing posts with label SQL SERVER FUNCTIONS. Show all posts

@@Functions in SQL SERVER

Posted in , | Leave a comment

@@LANGUAGE

@@LANGUAGE is a build in function in sql server which displayes information about the language that is being used in your instance of SQL SERVER.















Posted in , | Leave a comment

@@VERSION

@@VERSION  is an inbuild function which returns the version number of the sql server taht is running in your machine.




Posted in , | Leave a comment

@@SERVERNAME


@@SERVERNAME is an inbuild function in sql server which return the Server name as output.









Posted in , | Leave a comment

AVG in SQL SERVER

AVG is an aggregate function which is used to obtain the average of the values in a particular column.

Syntax:

SELECT AVG(<Column Name>) from <Table Name>

Example:

We have a table with the following data in the table SALES.

ITEMPRICE
ABC99.05
ABC1110.99
ABC270.89
ABC3100.99
ABC455.89


In order find out the average price of items in the sales we should use AVG function.

QUERY:

SELECT AVG(PRICE) FROM SALES

Result Set:
















Result set contains average of all the values in PRICE column.

Posted in , | Leave a comment

MIN in SQL SERVER

MIN is an aggregate function which is used to obtain the minimum value out of all the values in a particular column.
Syntax:

SELECT MIN (<Column Name>) from <Table Name>

Example:

We have a table with the following data in the table SALES.

ITEMPRICE
ABC99.05
ABC1110.99
ABC270.89
ABC3100.99
ABC455.89

In order find out the minimum price out of all the sales we should use MIN function.

QUERY:

SELECT MIN(PRICE) FROM SALES

Result Set:














Result set contains minimum value of all the values in PRICE column.

Posted in , | Leave a comment

MAX Function in SQL Server

MAX is an aggregate function which is used to obtain the maximum value out of all the values in a particular column.

Syntax:

SELECT MAX (<Column Name>) from <Table Name>

Example:

We have a table with the following data in the table SALES.

ITEMPRICE
ABC99.05
ABC1110.99
ABC270.89
ABC3100.99
ABC455.89

In order find out the maximum price out of all the sales we should use MAX function.

QUERY:

SELECT MAX(PRICE) FROM SALES

Result Set:













Result set contains maximum value of all the values in PRICE column.

Posted in , | Leave a comment

SUM in SQL Server

SUM is an aggregate function which is used to calculate the sum or total of values in a particular column.

Syntax:

SELECT SUM (<Column Name>) from <Table Name>

Example:

We have a table with the following data in the table SALES.

ITEMPRICE
ABC99.05
ABC1110.99
ABC270.89
ABC3100.99
ABC455.89


In order to count the total amount ( sum of the total prices) can be obtained by using SUM function.

QUERY:

SELECT SUM(PRICE) FROM SALES

Result Set:

Result set contains sum (total amount) of all the values in column PRICE.














Note:
  1. Sum function can be applied only on int , float , decimal , money data types.
  2. SUM Function ignores the NULL values in the columns.

Posted in , | Leave a comment

COUNT in SQL SERVER

COUNT is one of the most frequently used aggregate function in SQL SERVER.
As the indicated it counts the number of rows or records in the table.

Generally COUNT function is used to find out the number of rows in a table.
Syntax for the COUNT functions is:

SELECT COUNT(*) FROM <Table Name>
SELECT COUNT(1) FROM <Table Name>

Example:

Lets find out the number of rows in STUDENTS table using COUNT.

Query:

SELECT COUNT(*) FROM STUDENTS
SELECT COUNT(1) FROM STUDENTS 

Both of the above queries will return the same result.

Result Set:


Posted in , | Leave a comment

Aggregate Functions in SQL Server

Aggregate functions perform the calculation on the data and will return a single value as the out put.

In real time aggregate functions are used to calculate the minimum, maxmimum and average statistics.

HAVING Clause is mostly used to operate along with the aggregate functions.

Most frequently used Aggregate functions are:
Less frequently used aggregate functions are:
  • CHECKSUM
  • COUNT_BIG
  • CHECKSUM_AGG
  • BINARY_CHECKSUM
  • GROUPING
  • VAR
  • VARP
  • STDEV
  • STDEVP

Posted in , | Leave a comment