0% found this document useful (0 votes)
4 views3 pages

Batch22 SQLServerScript16

Uploaded by

himakailash1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Batch22 SQLServerScript16

Uploaded by

himakailash1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

/*

EOMONTH: It will display last date of that particular month use EOMONTH
Syntax: EOMONTH(ExistingDateColumn, no of months)
*/
select * from FirstTable1

select *,EOMONTH(ProductDate,-2) [EOMonth]from FirstTable1

select *,EOMONTH(ProductDate,3) [EOMonth]from FirstTable1

select *,EOMONTH(ProductDate,0) [EOMonth]from FirstTable1


/*
FORMAT: Format function is used in 3 different ways
1) Using Format function we can extract
DAY,WEEKNAME,MONTHNO,MONTHNAME,YEAR,WEEK,......
2) Using Format function we can display different date formates
3) Using Format function we can add currency symbol of numeric columns

1) Using Format function we can extract


DAY,WEEKNAME,MONTHNO,MONTHNAME,YEAR,WEEK,......
Syntax: FORMAT(ExistingDateColumn,'formatvalue')
*/
select * from FirstTable1

select *,FORMAT(ProductDate,'dd') [Day] from FirstTable1

select *,FORMAT(ProductDate,'ddd') [ShortWeekName] from FirstTable1

select *,FORMAT(ProductDate,'dddd') [WeekName] from FirstTable1

select *,FORMAT(ProductDate,'MM') [MonthNo] from FirstTable1

select *,FORMAT(ProductDate,'MMM') [ShortMonthName] from FirstTable1

select *,FORMAT(ProductDate,'MMMM') [MonthName] from FirstTable1

select *,FORMAT(ProductDate,'yy') [Year] from FirstTable1

select *,FORMAT(ProductDate,'yyyy') [Year] from FirstTable1

/*
2) Using Format function we can display different date formates
Syntax: FORMAT(ExistingDateColumn,Dateformat)
*/
select * from FirstTable1

select *,FORMAT(ProductDate,'dd-MM-yyyy') [Format]from FirstTable1

select *,FORMAT(ProductDate,'MM/dd/yyyy') [Format]from FirstTable1

/*
3) Using Format function we can add currency symbol of numeric columns
Syntax: FORMAT(NumericColumn,'CurrencySymbol#.#')
*/
Select * from FirstTable1

Select *,FORMAT(id,'£#') [Currency] from FirstTable1

/*
CONERT or CAST: Converting from 1 datatype to another datatype

Convert Syntax:CONVERT(Newdatatype,existingcolumnname)
Cast Syntax: CAST(Existingcolumnname as Newdatatype)
*/
select * from FirstTable1

select *,CONVERT(int,Id) [Convert] from FirstTable1

select *,CAST(Id as int) [Convert] from FirstTable1

/*
String Functions are
CONCAT,LOWER,UPPER,PATINDEX,CHARINDEX,LEFT,RIGHT,LEN,STUFF,TRIM,REPLACE,SUBSTRING

CONCAT: Combining multiple columns into single column use CONCAT


Syntax: CONCAT(Existingcolumnname,Existingcolumnname,....)
*/
select * from FirstTable1

select *,CONCAT(ID,ProductName,ProductDate) [Concat] from FirstTable1

select *,CONCAT(ID,':',ProductName,':',ProductDate) [Concat] from FirstTable1

/*
LOWER: Convert into small letters use LOWER
Syntax: LOWER(Charactercolumn)
*/
Select * from FirstTable1

Select *,LOWER(ProductName) [Lower] from FirstTable1


/*
UPPER: Convert into capital letters use UPPER
Syntax: UPPER(Charactercolumn)
*/
select * from FirstTable1

select *,UPPER(productname) [Upper] from FirstTable1

/*
LEFT: It will extract the characters from left side use LEFT function
Syntax: LEFT(Existingcolumnname,No of Characters)
*/
select * from FirstTable1

select *,LEFT(productname,3) [LEFT] from FirstTable1

/*
RIGHT: It will extract the characters from right side use RIGHT function
Syntax: RIGHT(Existingcolumnname,No of Characters)
*/
select * from FirstTable1

select *,right(productname,2) [RIGHT] from FirstTable1

/*
LEN: It will calculate total no of characters in each and every cell
Syntax: LEN(ExistingColumnname)
*/
select * from FirstTable1

select *,LEN(ProductName) [LEN] from FirstTable1

You might also like