SlideShare a Scribd company logo
1 of 8
Visit: www.gcrit.com for Software Testing Documents
String functions provided by SQL
server.
FUNCTION DESCRIPTION
Expression+expression[+expression] Concatenates two or more character or
binary strings.
ASCII (character_expression) Returns the ASCII value of the
characater expression
CHAR (integer_expression) Returns the character equivalent of the
ASCII code value.
Visit: QuickTest Professional for QTP 1
Visit: www.gcrit.com for Software Testing Documents
Date Functions:
The syntax is:
SELECT date_function(parameters)
FUNCTION DESCRIPTION
DATEADD(datepart, number, date) Adds the no.of dateparts to date.
DATEDIFF(datepart, date1, date2) Returns the number of dateparts
between two dates.
DATENAME(datepart, date) Returns the integer value of the date
part.
Visit: QuickTest Professional for QTP
CHARINDEX(‘pattern’, expression) Returns the starting position of the
specified pattern.
DIFFERENCE (character_expression1,
character_expression2)
Compares two straing and evaluates
the similarity between them on a scale
of 1 to 4.
LOWER (character_expression) Converts two string and evaluates the
similarity between them on a scale of 1
to 4.
LTRIM(character_expression) Returns the data with out leading
brackets
PATINDEX(‘%pattern’, expression) Returns the starting position of the first
occurrence of the pattern in the
specified expression, zero if the pattern
is not found.
REPLICATE(char_expression,
integer_expression
Repeats a character expression a
specified number of times.
REVERSE(character_expression) Returns the reverse of character
expression.
RIGHT(character_expression,
integer_expression)
Returns the part of the character string
from the right.
RTRIM(character_expression) Returns the data without tailing blanks.
SOUNDEX(character_expression) Returns the four-digit code to evaluate
the similarity of two character strings.
SPACE(numeric_expression) Returns a string of repeated spaces.
The number of spaces is equal to the
integer expression.
STR(float expression[,length[,decimal]]) Returns character data converted from
numeric data.
STUFF(charactaer_expression1,start,length,
character_expression)
Deletes length characters from first
character exspression at start and then
inserts character expression2 into
character expression.
UPPER(character_expression) Converts the character expression into
upper case.
2
Visit: www.gcrit.com for Software Testing Documents
DATEPART(datepart,date) Returns the integer value of the date
part.
GETDATE() Returns the current date and time.
Examples:
SELECT GETDATE()
The above statement displays the current system date and time with the help
of the GETDATE function.
SELECT DATEDIFF(yy,ord_date,getdate())
This statement uses the DATEDIFF function to find the difference between the
current date and the order_date, from sales tables. The difference should be
expressed in terms of number of years.
SELECT title, DATEPART(yy,pubdate) FROM titles.
The above statement uses the DATEPART function to return the year when the book
was published, along with the title name.
SELECT Title=title_id, Month=dATENAME(mm,pubdate), year=DATENAME(yy,
pubdatae) FROM titles.
Data Conversion:
SQL server handles certain datatype conversion automatically. If a character
expression is compared with an int expression, SQL server makes the conversion
automatically for the comparison(implicit conversion).
The CONVERT function is used to change data from one type to another when SQL
server cannot implicitly perform a conversion. Using the CONVERT function, data can
be modified in variety of styles.
The syntax is:
Aggregate Functions
Aggregate functions are used to produce summary data using tables.
Function Parameters Description
AVG (ALL/DISTINCT] expression Returns the average of values
specified in the expression, either
all records or distinct records
Visit: QuickTest Professional for QTP 3
SELECT Ytd_Sales=CONVERT(char(10),ytd_sales)
FROM titles.
SELECT CONVERT(int, zip) FROM authors
CONVERT(datatype[(length), expression[,style])
Visit: www.gcrit.com for Software Testing Documents
SUM (ALL/DISTINCT] expression) Returns the sum of values
specified in the expression, either
all records or distinct records.
MIN (expression) Returns the minimum of a value
specified in the expression.
MAX (expression) Returns the maximum of a value
specified in the expression.
COUNT (ALL| DISTINCT expression) Returns the number of unique or
all records specified in an
expression.
COUNT (*) Returns the total number of
records specified in an expression.
Examples of Aggregate functions
SELECT ‘Average Price”=AVG(price)
FROM titles
Returns the average value of all the
price values in the titles table with
user-defined heading.
SELECT ‘Sum’=SUM(DISTINCT
advance) FROM titles
Returns the sum value of all-the unique
advance values in the titles table with
user-defined heading.
SELECT ‘Minimum Ytd
Sales’=MIN(ytd_sales) FROM titles
Returns the minimum value of
ytd_sales value in the titles table with
user-defined heading.
SELECT ‘Maximum Ytd
Sales’=MAX(ytd_sales) FROM titles
Returns the maximum value of
ytd_sales in the titles table with user-
defined heading.
SELECT ‘Unique
Price’=COUNT(DISTINCT price) FROM
titles
Returns the number of unique price
values in the titles table with user-
defined heading.
SELECT ‘Price=COUNT(price) FROM
titles
Returns the number of total number of
price values in the titles with user-
defined heading.
Selecting Rows
There are situations in which only a few rows need to be retrieved from the
table based on a condition. The WHERE clause, is provided by SQL server, to specify
a condition.
The syntax for using the WHERE clause is:
Example:
Search Based On Conditions
Visit: QuickTest Professional for QTP 4
SELECT column_list FROM table_name WHERE search_condition
SELECT * FROM publishers WHERE state = ‘MA’
Visit: www.gcrit.com for Software Testing Documents
SQL Server provides few methods of searching rows in a table. These
methods can be broadly categorized into the following categories.
 Comparison operators like =, >, <, >=, <=, !=, !< and !>
 Range operators like BETWEEN and NOT BETWEEN.
 List operators line IN and NOT IN.
 String operators like LIKE and NOT LIKE.
 Unknown values like IS NULL and NOT NULL.
 Logical operators like AND , OR and NOT.
Comparison Operator
The command syntax is:
SELECT column_list FROM table_name WHERE expression1
comparison_operator expression2
Valid Comparison operators
Operator Description
= Equal to
> Greater than
< Less than
>= Greater than or Equal to
<= Less than or Equal to
<>, != Not Equal to
!> Not Greater than
!< Not Less than
() Controls Precedence
Examples:
Range Operator
The range operator is used to retrieve data that can be extracted in ranges.
The range operations are:
 BETWEEN
 NOT BETWEEN
The syntax is:
Visit: QuickTest Professional for QTP 5
SELECT title FROM titles WHERE type=’business’
SELECT stor_id, ord_num, title_id FROM sales WHERE qty>20
SELECT type, title_id, price FROM titles WHERE price * ytd_sales<advance.
SELECT column_list FROM table_name WHERE expression1 range_operator
expression2 AND expression2
Examples:
1. SELECT title from titles WHERE advance BETWEEN 2000 AND 5000
2. SELECT title FROM titles
WHERE advance NOT BETWEEN 4000 AND 5000
Visit: www.gcrit.com for Software Testing Documents
List Operator
The syntax is:
String Operator
SQL Server provides a pattern-matching method for string expressions using
the LIKE keyword with the wildcard characters. The LIKE keyword is used to select
those rows that match the specified portion of character string. The LIKE keyword
allows wildcard characters that can be used as a part of an expression.
Wild card Description
% Represents any string of zero or more characters(s)
- Represents a single character
[] Represents any single character within the specified range.
[^] Represents any single character not within the specified
range.
Examples of the LIKE operator with wildcards.
Example Description
SELECT title FROM titles WHERE
type LIKE ‘bus%’
Returns all titles from titles table where first
three characters of the column type are
‘bus’
SELECT * FROM publishers
WHERE country LIKE ‘US_’
Returns all rows from publishers table where
country name is three characters long and
starts with US where the third character can
be anything.
SELECT title_id, price FROM titles
WHERE title_id LIKE ‘P[SC]]%’
Returns all columns from the titles table
where title_id starts with the character P and
contains S or C in the second position
followed by any number of characters.
Visit: QuickTest Professional for QTP 6
SELECT column_list FROM table_name WHERE expression
list_operator(‘value_list’)
Examples:
1. SELECT pub_name, city, state FROM publishers
WHERE state IN (‘MA’, ‘DC’)
2. SELECT pub_name, city, state FROM publishers
WHERE state NOT IN (‘MA’, ‘DC’)
Visit: www.gcrit.com for Software Testing Documents
SELECT title_id, price FROM titles
WHERE title_id, LIKE ‘P[^C]%’
Returns all title_id and price from the titles
table where title_id starts with P and does
not contain and S as the second character
and the third position onwards can contain
any characters.
Unknown Values
Unknown values refer to the data entered in the form of the NULL keyword.
In SQL serve terms, NULL is an unknown value or the value for which data is not
available. The rows containing the NULL values can be retrieved by using the IS
NULL keyword in the WHERE clause.
The Syntax is:
SELECT column_list FROM table_name
WHERE column_name unknown_value_operator.
SELECT title, ytd_sales FROM titles WHERE ytd_sales IS NULL
Logical Operator
 OR – Returns the result when any of the specified search conditions is
true.
 AND – returns the result when all of the specified search conditions
are true.
 NOT – Bnegates the expression that follows it.
SELECT column_list FROM table_name
WHERE conditional_expression{ANDOR}[NOT] conditional_expression.
Examples of Logical operators
Example Description
SELECT * FROM publishers WHERE
city=’Boston’ OR city=’Paris’
Returns all the rows specific to the
conditions, even if any one of the
conditions is true.
SELECT publishers WHERE
city=’Boston’ AND city=’MA’
Returns all the rows specific to the
conditions, when both the conditions
are true.
SELECT * FROM publishers WHERE
city=’Boston’ OR NOT city=’Paris’
Returns all the rows specific to the
conditions, except the rows specified
with the condition after NOT operator.
Distinct
The distinct clause removes duplicate rows from the result set. Duplicate rows
can be eliminated by using the DISTINCT keyword in the SELECT statement.
Syntax:
Visit: QuickTest Professional for QTP 7
SELECT [ALL|DISTINCT] column_name
FROM table_name
WHERE search_condition
Example:
SELECT DISTINCT title_id
FROM titleauthor
WHERE title_id LIKE’PS%’
Visit: www.gcrit.com for Software Testing Documents
TOP and PERCENT
The TOP clause limits the number of rows returned in the result set.
The syntax is:
TOP n [PERCENT]
Where n specifies the number of rows are to be returned, if PERCENT is not
specified. If PERCENT is specified, n specifies the percentage of the rows to be
returned.
The TOP clause is used with the SELECT statement.
The following example returns the top 20 rows of the result set.
SELECT TOP 20
The next example returns the 10% of rows from top of the result set.
SELECT TOP 10 PERCENT
It the SELECT statement, including TOP, has and ORDER BY clause, then the rows
to be returned are selected after the ORDER BY statement has been applied.
Visit: QuickTest Professional for QTP 8

More Related Content

What's hot

SQL Functions and Operators
SQL Functions and OperatorsSQL Functions and Operators
SQL Functions and OperatorsMohan Kumar.R
 
Structured query language(sql)
Structured query language(sql)Structured query language(sql)
Structured query language(sql)Huda Alameen
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Trainingbixxman
 
Sql server ___________session 3(sql 2008)
Sql server  ___________session 3(sql 2008)Sql server  ___________session 3(sql 2008)
Sql server ___________session 3(sql 2008)Ehtisham Ali
 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Achmad Solichin
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive dataAmrit Kaur
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql newSANTOSH RATH
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 

What's hot (20)

SQL Functions and Operators
SQL Functions and OperatorsSQL Functions and Operators
SQL Functions and Operators
 
Structured query language(sql)
Structured query language(sql)Structured query language(sql)
Structured query language(sql)
 
Single row functions
Single row functionsSingle row functions
Single row functions
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
Les03
Les03Les03
Les03
 
Single row functions
Single row functionsSingle row functions
Single row functions
 
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek SharmaIntroduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
 
Sql operator
Sql operatorSql operator
Sql operator
 
Sql wksht-1
Sql wksht-1Sql wksht-1
Sql wksht-1
 
Sql server ___________session 3(sql 2008)
Sql server  ___________session 3(sql 2008)Sql server  ___________session 3(sql 2008)
Sql server ___________session 3(sql 2008)
 
Sql.pptx
Sql.pptxSql.pptx
Sql.pptx
 
SQL Data Manipulation
SQL Data ManipulationSQL Data Manipulation
SQL Data Manipulation
 
SQL
SQLSQL
SQL
 
Sql2005 Xml
Sql2005 XmlSql2005 Xml
Sql2005 Xml
 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql new
 
SQL
SQLSQL
SQL
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 

Viewers also liked

File System Operations
File System OperationsFile System Operations
File System OperationsG.C Reddy
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questionsrithustutorials
 
201 core java interview questions oo ps interview questions - javatpoint
201 core java interview questions   oo ps interview questions - javatpoint201 core java interview questions   oo ps interview questions - javatpoint
201 core java interview questions oo ps interview questions - javatpointravi tyagi
 
Java interview questions
Java interview questionsJava interview questions
Java interview questionsrithustutorials
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questionsVinay Kumar
 
Java object oriented programming - OOPS
Java object oriented programming - OOPSJava object oriented programming - OOPS
Java object oriented programming - OOPSrithustutorials
 
Selenium Tips & Tricks
Selenium Tips & TricksSelenium Tips & Tricks
Selenium Tips & TricksDave Haeffner
 
RajeswaraRao_Resume_3years
RajeswaraRao_Resume_3yearsRajeswaraRao_Resume_3years
RajeswaraRao_Resume_3yearsRajeswara K
 
Resume Shweta Subhedar Bhide
Resume Shweta Subhedar BhideResume Shweta Subhedar Bhide
Resume Shweta Subhedar BhideShwetaS
 
Niyati_Manual_Testing_ISTQB_Certified_Resume
Niyati_Manual_Testing_ISTQB_Certified_ResumeNiyati_Manual_Testing_ISTQB_Certified_Resume
Niyati_Manual_Testing_ISTQB_Certified_ResumeNiyati Madad
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobGaruda Trainings
 
Manual Testing
Manual TestingManual Testing
Manual TestingG.C Reddy
 
Practical Tips & Tricks for Selenium Test Automation
Practical Tips & Tricks for Selenium Test AutomationPractical Tips & Tricks for Selenium Test Automation
Practical Tips & Tricks for Selenium Test AutomationSauce Labs
 

Viewers also liked (18)

Chapter one
Chapter oneChapter one
Chapter one
 
File System Operations
File System OperationsFile System Operations
File System Operations
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questions
 
201 core java interview questions oo ps interview questions - javatpoint
201 core java interview questions   oo ps interview questions - javatpoint201 core java interview questions   oo ps interview questions - javatpoint
201 core java interview questions oo ps interview questions - javatpoint
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questions
 
Java object oriented programming - OOPS
Java object oriented programming - OOPSJava object oriented programming - OOPS
Java object oriented programming - OOPS
 
Manual testing
Manual testingManual testing
Manual testing
 
Selenium Tips & Tricks
Selenium Tips & TricksSelenium Tips & Tricks
Selenium Tips & Tricks
 
RajeswaraRao_Resume_3years
RajeswaraRao_Resume_3yearsRajeswaraRao_Resume_3years
RajeswaraRao_Resume_3years
 
Introduction to Selenium Web Driver
Introduction to Selenium Web DriverIntroduction to Selenium Web Driver
Introduction to Selenium Web Driver
 
Resume Shweta Subhedar Bhide
Resume Shweta Subhedar BhideResume Shweta Subhedar Bhide
Resume Shweta Subhedar Bhide
 
Java programming-examples
Java programming-examplesJava programming-examples
Java programming-examples
 
Niyati_Manual_Testing_ISTQB_Certified_Resume
Niyati_Manual_Testing_ISTQB_Certified_ResumeNiyati_Manual_Testing_ISTQB_Certified_Resume
Niyati_Manual_Testing_ISTQB_Certified_Resume
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a job
 
Manual Testing
Manual TestingManual Testing
Manual Testing
 
Practical Tips & Tricks for Selenium Test Automation
Practical Tips & Tricks for Selenium Test AutomationPractical Tips & Tricks for Selenium Test Automation
Practical Tips & Tricks for Selenium Test Automation
 

Similar to Sql functions (20)

ADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptxADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptx
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptx
 
Ejb5
Ejb5Ejb5
Ejb5
 
Mysql1
Mysql1Mysql1
Mysql1
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 
Sql
SqlSql
Sql
 
Query
QueryQuery
Query
 
Unit04 dbms
Unit04 dbmsUnit04 dbms
Unit04 dbms
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
Intro to tsql unit 10
Intro to tsql   unit 10Intro to tsql   unit 10
Intro to tsql unit 10
 
SQL for pattern matching (Oracle 12c)
SQL for pattern matching (Oracle 12c)SQL for pattern matching (Oracle 12c)
SQL for pattern matching (Oracle 12c)
 
Oracle_Analytical_function.pdf
Oracle_Analytical_function.pdfOracle_Analytical_function.pdf
Oracle_Analytical_function.pdf
 
Sql
SqlSql
Sql
 
Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)
 
Cheat Sheet for Stata v15.00 PDF Complete
Cheat Sheet for Stata v15.00 PDF CompleteCheat Sheet for Stata v15.00 PDF Complete
Cheat Sheet for Stata v15.00 PDF Complete
 
SQL.pptx
SQL.pptxSQL.pptx
SQL.pptx
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
 
SQL : introduction
SQL : introductionSQL : introduction
SQL : introduction
 
7a advanced tsql
7a   advanced tsql7a   advanced tsql
7a advanced tsql
 

More from G C Reddy Technologies (6)

Free Classified Ads
Free Classified AdsFree Classified Ads
Free Classified Ads
 
Load runner
Load runnerLoad runner
Load runner
 
Excel Scripting
Excel Scripting Excel Scripting
Excel Scripting
 
Qtp launch
Qtp launchQtp launch
Qtp launch
 
Qtp Resume
Qtp ResumeQtp Resume
Qtp Resume
 
Qtp Resume
Qtp ResumeQtp Resume
Qtp Resume
 

Recently uploaded

(办理学位证)韩国汉阳大学毕业证成绩单原版一比一
(办理学位证)韩国汉阳大学毕业证成绩单原版一比一(办理学位证)韩国汉阳大学毕业证成绩单原版一比一
(办理学位证)韩国汉阳大学毕业证成绩单原版一比一C SSS
 
威廉玛丽学院毕业证学位证成绩单-安全学历认证
威廉玛丽学院毕业证学位证成绩单-安全学历认证威廉玛丽学院毕业证学位证成绩单-安全学历认证
威廉玛丽学院毕业证学位证成绩单-安全学历认证kbdhl05e
 
(办理学位证)加州州立大学北岭分校毕业证成绩单原版一比一
(办理学位证)加州州立大学北岭分校毕业证成绩单原版一比一(办理学位证)加州州立大学北岭分校毕业证成绩单原版一比一
(办理学位证)加州州立大学北岭分校毕业证成绩单原版一比一Fi sss
 
Real Sure (Call Girl) in I.G.I. Airport 8377087607 Hot Call Girls In Delhi NCR
Real Sure (Call Girl) in I.G.I. Airport 8377087607 Hot Call Girls In Delhi NCRReal Sure (Call Girl) in I.G.I. Airport 8377087607 Hot Call Girls In Delhi NCR
Real Sure (Call Girl) in I.G.I. Airport 8377087607 Hot Call Girls In Delhi NCRdollysharma2066
 
Call Girls In Munirka>༒9599632723 Incall_OutCall Available
Call Girls In Munirka>༒9599632723 Incall_OutCall AvailableCall Girls In Munirka>༒9599632723 Incall_OutCall Available
Call Girls In Munirka>༒9599632723 Incall_OutCall AvailableCall Girls in Delhi
 
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degreeyuu sss
 
Hifi Defence Colony Call Girls Service WhatsApp -> 9999965857 Available 24x7 ...
Hifi Defence Colony Call Girls Service WhatsApp -> 9999965857 Available 24x7 ...Hifi Defence Colony Call Girls Service WhatsApp -> 9999965857 Available 24x7 ...
Hifi Defence Colony Call Girls Service WhatsApp -> 9999965857 Available 24x7 ...srsj9000
 
毕业文凭制作#回国入职#diploma#degree加拿大瑞尔森大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree加拿大瑞尔森大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree 毕业文凭制作#回国入职#diploma#degree加拿大瑞尔森大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree加拿大瑞尔森大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree z zzz
 
NO1 WorldWide kala jadu Love Marriage Black Magic Punjab Powerful Black Magic...
NO1 WorldWide kala jadu Love Marriage Black Magic Punjab Powerful Black Magic...NO1 WorldWide kala jadu Love Marriage Black Magic Punjab Powerful Black Magic...
NO1 WorldWide kala jadu Love Marriage Black Magic Punjab Powerful Black Magic...Amil baba
 
Papular No 1 Online Istikhara Amil Baba Pakistan Amil Baba In Karachi Amil B...
Papular No 1 Online Istikhara Amil Baba Pakistan  Amil Baba In Karachi Amil B...Papular No 1 Online Istikhara Amil Baba Pakistan  Amil Baba In Karachi Amil B...
Papular No 1 Online Istikhara Amil Baba Pakistan Amil Baba In Karachi Amil B...Authentic No 1 Amil Baba In Pakistan
 
NO1 Qualified Best Black Magic Specialist Near Me Spiritual Healer Powerful L...
NO1 Qualified Best Black Magic Specialist Near Me Spiritual Healer Powerful L...NO1 Qualified Best Black Magic Specialist Near Me Spiritual Healer Powerful L...
NO1 Qualified Best Black Magic Specialist Near Me Spiritual Healer Powerful L...Amil baba
 
定制(USF学位证)旧金山大学毕业证成绩单原版一比一
定制(USF学位证)旧金山大学毕业证成绩单原版一比一定制(USF学位证)旧金山大学毕业证成绩单原版一比一
定制(USF学位证)旧金山大学毕业证成绩单原版一比一ss ss
 
RBS学位证,鹿特丹商学院毕业证书1:1制作
RBS学位证,鹿特丹商学院毕业证书1:1制作RBS学位证,鹿特丹商学院毕业证书1:1制作
RBS学位证,鹿特丹商学院毕业证书1:1制作f3774p8b
 
Call Girls Delhi {Rohini} 9711199012 high profile service
Call Girls Delhi {Rohini} 9711199012 high profile serviceCall Girls Delhi {Rohini} 9711199012 high profile service
Call Girls Delhi {Rohini} 9711199012 high profile servicerehmti665
 
(办理学位证)多伦多大学毕业证成绩单原版一比一
(办理学位证)多伦多大学毕业证成绩单原版一比一(办理学位证)多伦多大学毕业证成绩单原版一比一
(办理学位证)多伦多大学毕业证成绩单原版一比一C SSS
 
萨斯喀彻温大学毕业证学位证成绩单-购买流程
萨斯喀彻温大学毕业证学位证成绩单-购买流程萨斯喀彻温大学毕业证学位证成绩单-购买流程
萨斯喀彻温大学毕业证学位证成绩单-购买流程1k98h0e1
 
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...nagunakhan
 
Gaya Call Girls #9907093804 Contact Number Escorts Service Gaya
Gaya Call Girls #9907093804 Contact Number Escorts Service GayaGaya Call Girls #9907093804 Contact Number Escorts Service Gaya
Gaya Call Girls #9907093804 Contact Number Escorts Service Gayasrsj9000
 

Recently uploaded (20)

(办理学位证)韩国汉阳大学毕业证成绩单原版一比一
(办理学位证)韩国汉阳大学毕业证成绩单原版一比一(办理学位证)韩国汉阳大学毕业证成绩单原版一比一
(办理学位证)韩国汉阳大学毕业证成绩单原版一比一
 
CIVIL ENGINEERING
CIVIL ENGINEERINGCIVIL ENGINEERING
CIVIL ENGINEERING
 
威廉玛丽学院毕业证学位证成绩单-安全学历认证
威廉玛丽学院毕业证学位证成绩单-安全学历认证威廉玛丽学院毕业证学位证成绩单-安全学历认证
威廉玛丽学院毕业证学位证成绩单-安全学历认证
 
(办理学位证)加州州立大学北岭分校毕业证成绩单原版一比一
(办理学位证)加州州立大学北岭分校毕业证成绩单原版一比一(办理学位证)加州州立大学北岭分校毕业证成绩单原版一比一
(办理学位证)加州州立大学北岭分校毕业证成绩单原版一比一
 
Real Sure (Call Girl) in I.G.I. Airport 8377087607 Hot Call Girls In Delhi NCR
Real Sure (Call Girl) in I.G.I. Airport 8377087607 Hot Call Girls In Delhi NCRReal Sure (Call Girl) in I.G.I. Airport 8377087607 Hot Call Girls In Delhi NCR
Real Sure (Call Girl) in I.G.I. Airport 8377087607 Hot Call Girls In Delhi NCR
 
Call Girls In Munirka>༒9599632723 Incall_OutCall Available
Call Girls In Munirka>༒9599632723 Incall_OutCall AvailableCall Girls In Munirka>༒9599632723 Incall_OutCall Available
Call Girls In Munirka>༒9599632723 Incall_OutCall Available
 
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
 
Hifi Defence Colony Call Girls Service WhatsApp -> 9999965857 Available 24x7 ...
Hifi Defence Colony Call Girls Service WhatsApp -> 9999965857 Available 24x7 ...Hifi Defence Colony Call Girls Service WhatsApp -> 9999965857 Available 24x7 ...
Hifi Defence Colony Call Girls Service WhatsApp -> 9999965857 Available 24x7 ...
 
毕业文凭制作#回国入职#diploma#degree加拿大瑞尔森大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree加拿大瑞尔森大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree 毕业文凭制作#回国入职#diploma#degree加拿大瑞尔森大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree加拿大瑞尔森大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
 
NO1 WorldWide kala jadu Love Marriage Black Magic Punjab Powerful Black Magic...
NO1 WorldWide kala jadu Love Marriage Black Magic Punjab Powerful Black Magic...NO1 WorldWide kala jadu Love Marriage Black Magic Punjab Powerful Black Magic...
NO1 WorldWide kala jadu Love Marriage Black Magic Punjab Powerful Black Magic...
 
Papular No 1 Online Istikhara Amil Baba Pakistan Amil Baba In Karachi Amil B...
Papular No 1 Online Istikhara Amil Baba Pakistan  Amil Baba In Karachi Amil B...Papular No 1 Online Istikhara Amil Baba Pakistan  Amil Baba In Karachi Amil B...
Papular No 1 Online Istikhara Amil Baba Pakistan Amil Baba In Karachi Amil B...
 
NO1 Qualified Best Black Magic Specialist Near Me Spiritual Healer Powerful L...
NO1 Qualified Best Black Magic Specialist Near Me Spiritual Healer Powerful L...NO1 Qualified Best Black Magic Specialist Near Me Spiritual Healer Powerful L...
NO1 Qualified Best Black Magic Specialist Near Me Spiritual Healer Powerful L...
 
young call girls in Khanpur,🔝 9953056974 🔝 escort Service
young call girls in  Khanpur,🔝 9953056974 🔝 escort Serviceyoung call girls in  Khanpur,🔝 9953056974 🔝 escort Service
young call girls in Khanpur,🔝 9953056974 🔝 escort Service
 
定制(USF学位证)旧金山大学毕业证成绩单原版一比一
定制(USF学位证)旧金山大学毕业证成绩单原版一比一定制(USF学位证)旧金山大学毕业证成绩单原版一比一
定制(USF学位证)旧金山大学毕业证成绩单原版一比一
 
RBS学位证,鹿特丹商学院毕业证书1:1制作
RBS学位证,鹿特丹商学院毕业证书1:1制作RBS学位证,鹿特丹商学院毕业证书1:1制作
RBS学位证,鹿特丹商学院毕业证书1:1制作
 
Call Girls Delhi {Rohini} 9711199012 high profile service
Call Girls Delhi {Rohini} 9711199012 high profile serviceCall Girls Delhi {Rohini} 9711199012 high profile service
Call Girls Delhi {Rohini} 9711199012 high profile service
 
(办理学位证)多伦多大学毕业证成绩单原版一比一
(办理学位证)多伦多大学毕业证成绩单原版一比一(办理学位证)多伦多大学毕业证成绩单原版一比一
(办理学位证)多伦多大学毕业证成绩单原版一比一
 
萨斯喀彻温大学毕业证学位证成绩单-购买流程
萨斯喀彻温大学毕业证学位证成绩单-购买流程萨斯喀彻温大学毕业证学位证成绩单-购买流程
萨斯喀彻温大学毕业证学位证成绩单-购买流程
 
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...
 
Gaya Call Girls #9907093804 Contact Number Escorts Service Gaya
Gaya Call Girls #9907093804 Contact Number Escorts Service GayaGaya Call Girls #9907093804 Contact Number Escorts Service Gaya
Gaya Call Girls #9907093804 Contact Number Escorts Service Gaya
 

Sql functions

  • 1. Visit: www.gcrit.com for Software Testing Documents String functions provided by SQL server. FUNCTION DESCRIPTION Expression+expression[+expression] Concatenates two or more character or binary strings. ASCII (character_expression) Returns the ASCII value of the characater expression CHAR (integer_expression) Returns the character equivalent of the ASCII code value. Visit: QuickTest Professional for QTP 1
  • 2. Visit: www.gcrit.com for Software Testing Documents Date Functions: The syntax is: SELECT date_function(parameters) FUNCTION DESCRIPTION DATEADD(datepart, number, date) Adds the no.of dateparts to date. DATEDIFF(datepart, date1, date2) Returns the number of dateparts between two dates. DATENAME(datepart, date) Returns the integer value of the date part. Visit: QuickTest Professional for QTP CHARINDEX(‘pattern’, expression) Returns the starting position of the specified pattern. DIFFERENCE (character_expression1, character_expression2) Compares two straing and evaluates the similarity between them on a scale of 1 to 4. LOWER (character_expression) Converts two string and evaluates the similarity between them on a scale of 1 to 4. LTRIM(character_expression) Returns the data with out leading brackets PATINDEX(‘%pattern’, expression) Returns the starting position of the first occurrence of the pattern in the specified expression, zero if the pattern is not found. REPLICATE(char_expression, integer_expression Repeats a character expression a specified number of times. REVERSE(character_expression) Returns the reverse of character expression. RIGHT(character_expression, integer_expression) Returns the part of the character string from the right. RTRIM(character_expression) Returns the data without tailing blanks. SOUNDEX(character_expression) Returns the four-digit code to evaluate the similarity of two character strings. SPACE(numeric_expression) Returns a string of repeated spaces. The number of spaces is equal to the integer expression. STR(float expression[,length[,decimal]]) Returns character data converted from numeric data. STUFF(charactaer_expression1,start,length, character_expression) Deletes length characters from first character exspression at start and then inserts character expression2 into character expression. UPPER(character_expression) Converts the character expression into upper case. 2
  • 3. Visit: www.gcrit.com for Software Testing Documents DATEPART(datepart,date) Returns the integer value of the date part. GETDATE() Returns the current date and time. Examples: SELECT GETDATE() The above statement displays the current system date and time with the help of the GETDATE function. SELECT DATEDIFF(yy,ord_date,getdate()) This statement uses the DATEDIFF function to find the difference between the current date and the order_date, from sales tables. The difference should be expressed in terms of number of years. SELECT title, DATEPART(yy,pubdate) FROM titles. The above statement uses the DATEPART function to return the year when the book was published, along with the title name. SELECT Title=title_id, Month=dATENAME(mm,pubdate), year=DATENAME(yy, pubdatae) FROM titles. Data Conversion: SQL server handles certain datatype conversion automatically. If a character expression is compared with an int expression, SQL server makes the conversion automatically for the comparison(implicit conversion). The CONVERT function is used to change data from one type to another when SQL server cannot implicitly perform a conversion. Using the CONVERT function, data can be modified in variety of styles. The syntax is: Aggregate Functions Aggregate functions are used to produce summary data using tables. Function Parameters Description AVG (ALL/DISTINCT] expression Returns the average of values specified in the expression, either all records or distinct records Visit: QuickTest Professional for QTP 3 SELECT Ytd_Sales=CONVERT(char(10),ytd_sales) FROM titles. SELECT CONVERT(int, zip) FROM authors CONVERT(datatype[(length), expression[,style])
  • 4. Visit: www.gcrit.com for Software Testing Documents SUM (ALL/DISTINCT] expression) Returns the sum of values specified in the expression, either all records or distinct records. MIN (expression) Returns the minimum of a value specified in the expression. MAX (expression) Returns the maximum of a value specified in the expression. COUNT (ALL| DISTINCT expression) Returns the number of unique or all records specified in an expression. COUNT (*) Returns the total number of records specified in an expression. Examples of Aggregate functions SELECT ‘Average Price”=AVG(price) FROM titles Returns the average value of all the price values in the titles table with user-defined heading. SELECT ‘Sum’=SUM(DISTINCT advance) FROM titles Returns the sum value of all-the unique advance values in the titles table with user-defined heading. SELECT ‘Minimum Ytd Sales’=MIN(ytd_sales) FROM titles Returns the minimum value of ytd_sales value in the titles table with user-defined heading. SELECT ‘Maximum Ytd Sales’=MAX(ytd_sales) FROM titles Returns the maximum value of ytd_sales in the titles table with user- defined heading. SELECT ‘Unique Price’=COUNT(DISTINCT price) FROM titles Returns the number of unique price values in the titles table with user- defined heading. SELECT ‘Price=COUNT(price) FROM titles Returns the number of total number of price values in the titles with user- defined heading. Selecting Rows There are situations in which only a few rows need to be retrieved from the table based on a condition. The WHERE clause, is provided by SQL server, to specify a condition. The syntax for using the WHERE clause is: Example: Search Based On Conditions Visit: QuickTest Professional for QTP 4 SELECT column_list FROM table_name WHERE search_condition SELECT * FROM publishers WHERE state = ‘MA’
  • 5. Visit: www.gcrit.com for Software Testing Documents SQL Server provides few methods of searching rows in a table. These methods can be broadly categorized into the following categories.  Comparison operators like =, >, <, >=, <=, !=, !< and !>  Range operators like BETWEEN and NOT BETWEEN.  List operators line IN and NOT IN.  String operators like LIKE and NOT LIKE.  Unknown values like IS NULL and NOT NULL.  Logical operators like AND , OR and NOT. Comparison Operator The command syntax is: SELECT column_list FROM table_name WHERE expression1 comparison_operator expression2 Valid Comparison operators Operator Description = Equal to > Greater than < Less than >= Greater than or Equal to <= Less than or Equal to <>, != Not Equal to !> Not Greater than !< Not Less than () Controls Precedence Examples: Range Operator The range operator is used to retrieve data that can be extracted in ranges. The range operations are:  BETWEEN  NOT BETWEEN The syntax is: Visit: QuickTest Professional for QTP 5 SELECT title FROM titles WHERE type=’business’ SELECT stor_id, ord_num, title_id FROM sales WHERE qty>20 SELECT type, title_id, price FROM titles WHERE price * ytd_sales<advance. SELECT column_list FROM table_name WHERE expression1 range_operator expression2 AND expression2 Examples: 1. SELECT title from titles WHERE advance BETWEEN 2000 AND 5000 2. SELECT title FROM titles WHERE advance NOT BETWEEN 4000 AND 5000
  • 6. Visit: www.gcrit.com for Software Testing Documents List Operator The syntax is: String Operator SQL Server provides a pattern-matching method for string expressions using the LIKE keyword with the wildcard characters. The LIKE keyword is used to select those rows that match the specified portion of character string. The LIKE keyword allows wildcard characters that can be used as a part of an expression. Wild card Description % Represents any string of zero or more characters(s) - Represents a single character [] Represents any single character within the specified range. [^] Represents any single character not within the specified range. Examples of the LIKE operator with wildcards. Example Description SELECT title FROM titles WHERE type LIKE ‘bus%’ Returns all titles from titles table where first three characters of the column type are ‘bus’ SELECT * FROM publishers WHERE country LIKE ‘US_’ Returns all rows from publishers table where country name is three characters long and starts with US where the third character can be anything. SELECT title_id, price FROM titles WHERE title_id LIKE ‘P[SC]]%’ Returns all columns from the titles table where title_id starts with the character P and contains S or C in the second position followed by any number of characters. Visit: QuickTest Professional for QTP 6 SELECT column_list FROM table_name WHERE expression list_operator(‘value_list’) Examples: 1. SELECT pub_name, city, state FROM publishers WHERE state IN (‘MA’, ‘DC’) 2. SELECT pub_name, city, state FROM publishers WHERE state NOT IN (‘MA’, ‘DC’)
  • 7. Visit: www.gcrit.com for Software Testing Documents SELECT title_id, price FROM titles WHERE title_id, LIKE ‘P[^C]%’ Returns all title_id and price from the titles table where title_id starts with P and does not contain and S as the second character and the third position onwards can contain any characters. Unknown Values Unknown values refer to the data entered in the form of the NULL keyword. In SQL serve terms, NULL is an unknown value or the value for which data is not available. The rows containing the NULL values can be retrieved by using the IS NULL keyword in the WHERE clause. The Syntax is: SELECT column_list FROM table_name WHERE column_name unknown_value_operator. SELECT title, ytd_sales FROM titles WHERE ytd_sales IS NULL Logical Operator  OR – Returns the result when any of the specified search conditions is true.  AND – returns the result when all of the specified search conditions are true.  NOT – Bnegates the expression that follows it. SELECT column_list FROM table_name WHERE conditional_expression{ANDOR}[NOT] conditional_expression. Examples of Logical operators Example Description SELECT * FROM publishers WHERE city=’Boston’ OR city=’Paris’ Returns all the rows specific to the conditions, even if any one of the conditions is true. SELECT publishers WHERE city=’Boston’ AND city=’MA’ Returns all the rows specific to the conditions, when both the conditions are true. SELECT * FROM publishers WHERE city=’Boston’ OR NOT city=’Paris’ Returns all the rows specific to the conditions, except the rows specified with the condition after NOT operator. Distinct The distinct clause removes duplicate rows from the result set. Duplicate rows can be eliminated by using the DISTINCT keyword in the SELECT statement. Syntax: Visit: QuickTest Professional for QTP 7 SELECT [ALL|DISTINCT] column_name FROM table_name WHERE search_condition Example: SELECT DISTINCT title_id FROM titleauthor WHERE title_id LIKE’PS%’
  • 8. Visit: www.gcrit.com for Software Testing Documents TOP and PERCENT The TOP clause limits the number of rows returned in the result set. The syntax is: TOP n [PERCENT] Where n specifies the number of rows are to be returned, if PERCENT is not specified. If PERCENT is specified, n specifies the percentage of the rows to be returned. The TOP clause is used with the SELECT statement. The following example returns the top 20 rows of the result set. SELECT TOP 20 The next example returns the 10% of rows from top of the result set. SELECT TOP 10 PERCENT It the SELECT statement, including TOP, has and ORDER BY clause, then the rows to be returned are selected after the ORDER BY statement has been applied. Visit: QuickTest Professional for QTP 8