SlideShare a Scribd company logo
Top 5 Built-in Functions
    (Transact-SQL)




               Manas Ranjan Dash




                              @simplymanas
Agenda



Programmability Enhancements (Database Engine)

select (my) top 5 * from SQL_BuiltIn_Functions




  **All the function described in this session are purely related to SQL2012.
  There is no resemblance with SQL2005 or SQL2008. Compatibility level 110
What is today’s date?
What is tomorrow’s date?



    SELECT GETDATE()

   SELECT GETDATE()+1
Beginning of the month?



SELECT CAST (
CAST (YEAR(GETDATE()) AS VARCHAR) + '-'+
CAST(MONTH(GETDATE()) AS VARCHAR) + '-'+
 '01' AS DATE)
Beginning of the month?

    I am from
     SQL 2012

 SELECT CAST(
 CONCAT(
 YEAR(GETDATE()),'-',
 MONTH(GETDATE()),'-',
 '01')
 AS DATE)
Display Full Name

     SQL
   SERVER
    2012
SELECT
SELECT
CONCAT(
  FIRSTNAME +' ' +
  ISNULL(FIRSTNAME,'') +' ' +
  FIRSTNAME,' ',
  MIDDLENAME + ' ' +
  ISNULL(MIDDLENAME,'') + ' ' +
  MIDDLENAME,' ',
  LASTNAME AS FULLNAME AS FULLNAME
  ISNULL(LASTTNAME,'')
  LASTNAME
FROM PERSON.PERSON
  ) AS FULLNAME
FROM PERSON.PERSON
CONCAT() Function



                    BOL
 CONCAT ( string_value1, string_value2 [, string_valueN ] )
 All arguments are implicitly converted to string types and then
   concatenated.
                  BACHCHAN
 Null values are implicitly converted to an empty string.
 If all the arguments are null, an empty string of type varchar(1)
   is returned.


                                                 TOP 1
Beginning of the month?

            SQL
SELECT CAST (
          SERVER
           2012
  CONCAT
SELECT
  (
  DATEFROMPARTS (
     YEAR(GETDATE()),'-',
     YEAR(GETDATE()),
     MONTH(GETDATE()),'-',
     MONTH(GETDATE()),
     '01'
     1)
  )
AS DATE)
DATEFROMPARTS() Function




                    BOL
 DATEFROMPARTS ( year, month, day )
 DATEFROMPARTS returns a date value with the date portion

                BACHCHAN
   set to the specified year, month and day.




                                               TOP 2
End of the month?

  SELECT DATEADD
      SQL
SELECT DATEADD
       (D,-1,
    SERVER
   (D,-1, DATEADD
     2012 DATEFROMPARTS(
   SELECT
          CASE WHEN MONTH(GETDATE())<12
   DATEFROMPARTS(
   (D,-1, YEAR(GETDATE())
          THEN DECEMBER
   IIF(MONTH(GETDATE())<12,
   DATEFROMPARTS(YEAR(GETDATE()),
          ELSE YEAR(GETDATE())+1
        YEAR(GETDATE()),YEAR(GETDATE()+1)),
          END,
   MONTH(GETDATE())+1,1) MONTH(GETDATE())+1),
   IIF(MONTH(GETDATE())=12,1,
          CASE WHEN MONTH(GETDATE())=12 THEN 1
   )
   1)     ELSE MONTH(GETDATE())+1
)         END,
       1)
  )
IIF() Function




                     BOL
 IIF ( boolean_expression, true_value, false_value)
 IIF is translated into CASE

                 BACHCHAN
 IIF statements can also be nested only up to the maximum
   level of 10 like CASE.




                                               TOP 3
End of the month?

             SQL
--THIS MONTH SERVER
              END
SELECT DATEADD
SELECT EOMONTH(GETDATE())
              2012
   (D,-1,
--NEXT MONTH END
   DATEFROMPARTS(
SELECT EOMONTH(GETDATE(),1)
   IIF(MONTH(GETDATE())<12,
SELECT EOMONTH(GETDATE(),2)
      YEAR(GETDATE()),YEAR(GETDATE()+1)),
SELECT EOMONTH(GETDATE(),14)
   IIF(MONTH(GETDATE())=12,1, MONTH(GETDATE())+1),
--PREVIOUS MONTH END
   1)
SELECT EOMONTH(GETDATE(),-1)
)
SELECT EOMONTH(GETDATE(),-2)
SELECT EOMONTH(GETDATE(),-14)
EOMONTH() Function




                    BOL
 EOMONTH ( start_date [, month_to_add ] )
 Even if you pass a string parameter you will get a date return
  type as it does a implicit conversion.


                BACHCHAN
DECLARE @date VARCHAR(255)
SET @date = '12/1/2011'
SELECT EOMONTH ( @date ) AS Result
GO



                                                TOP 4
Lets Format a Date


  SELECT   CONVERT(VARCHAR,   GETDATE(),   101)   --11/23/2012
  SELECT   CONVERT(VARCHAR,   GETDATE(),   102)   --2012.11.23
  SELECT   CONVERT(VARCHAR,   GETDATE(),   103)   --23/11/2012
              SQL
  SELECT   CONVERT(VARCHAR,   GETDATE(),   104)   --23.11.2012
            SERVER
  SELECT   CONVERT(VARCHAR,
             2012
                              GETDATE(),   105)   --23-11-2012
  SELECT   CONVERT(VARCHAR,   GETDATE(),   108)   --10:04:52

SELECT FORMAT( GETDATE(), 'yyyy-MM-dd HH:MM') --2012-11-23 10:11
SELECT FORMAT( GETDATE(),' "First SQLUG Meet On" ddd dd"th" MMMM
yyyy "at" HH:MM ')
-- First SQLUG Meet On Fri 24th November 2012 at 10:11
FORMAT() Function




                   BOL
 FORMAT ( value, format [, culture ] )


                BACHCHAN
 Use the FORMAT function for locale-aware formatting of
  date/time and number values as strings. For general data type
  conversions, use CAST or CONVERT.




                                              TOP 5
CULTURE


 You can use the SET LANGUAGE statement.
 Culture accepts any culture supported by the .NET Framework
  as an argument;
 it is not limited to the languages explicitly supported by SQL
  Server

DECLARE @d DATETIME   = '01/01/2011';
SELECT FORMAT ( @d,   'd', 'en-US' ) AS   'US English Result'
      ,FORMAT ( @d,   'd', 'en-gb' ) AS   'Great Britain English Result'
      ,FORMAT ( @d,   'd', 'de-de' ) AS   'German Result'
      ,FORMAT ( @d,   'd', 'zh-cn' ) AS   'Simplified Chinese (PRC) Result';
NEWLY ADDED FUNCTIONS


Conversion functions
PARSE ()
TRY_CONVERT ()
TRY_PARSE ()
Date and time functions
DATEFROMPARTS ()
DATETIME2FROMPARTS ()        Logical functions
DATETIMEFROMPARTS ()         CHOOSE ()
DATETIMEOFFSETFROMPARTS ()   IIF ()
                                                 The existing LOG (Transact-
EOMONTH ()                   String functions    SQL) function now has an
SMALLDATETIMEFROMPARTS ()    CONCAT ()           optional second base parameter.
TIMEFROMPARTS ()             FORMAT ()           LOG ( float_expression [, base ] )
Q&A




 Best Reference: Books Online
http://msdn.microsoft.com/en-us/library/bb510741.aspx
simplymanas@gmail.com
         @simplymanas
Inspired by
Vinod Kumar, Jacob Sebastian, Pinal Dave

More Related Content

Similar to Top5 functions sql2012

TSQL Functions (SQL Server)
TSQL Functions (SQL Server)TSQL Functions (SQL Server)
TSQL Functions (SQL Server)
Steve Stedman
 
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
MariaDB plc
 
New Features of SQL Server 2016
New Features of SQL Server 2016New Features of SQL Server 2016
New Features of SQL Server 2016Mir Mahmood
 
Developers' New features of Sql server express 2012
Developers' New features of Sql server express 2012Developers' New features of Sql server express 2012
Developers' New features of Sql server express 2012Ziaur Rahman
 
SQL Server part 1 (6).pptx
SQL Server part 1 (6).pptxSQL Server part 1 (6).pptx
SQL Server part 1 (6).pptx
deepneuron
 
My Business Intelligence Portfolio
My Business Intelligence PortfolioMy Business Intelligence Portfolio
My Business Intelligence Portfolio
lfinkel
 
Jaime\'s Business Intelligence Portfolio
Jaime\'s Business Intelligence PortfolioJaime\'s Business Intelligence Portfolio
Jaime\'s Business Intelligence Portfoliojaimecarlson
 
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_103 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
mlraviol
 
SQL Server 2008 Overview
SQL Server 2008 OverviewSQL Server 2008 Overview
SQL Server 2008 Overview
Eric Nelson
 
What's New for Developers in SQL Server 2008?
What's New for Developers in SQL Server 2008?What's New for Developers in SQL Server 2008?
What's New for Developers in SQL Server 2008?ukdpe
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
Takayuki Goto
 
MDI Training DB2 Course
MDI Training DB2 CourseMDI Training DB2 Course
MDI Training DB2 CourseMarcus Davage
 
IBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql FeaturesIBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql Features
Keshav Murthy
 
Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)Jay Patel
 
Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)Jay Patel
 
Uncovering SQL Server query problems with execution plans - Tony Davis
Uncovering SQL Server query problems with execution plans - Tony DavisUncovering SQL Server query problems with execution plans - Tony Davis
Uncovering SQL Server query problems with execution plans - Tony Davis
Red Gate Software
 
Sql server ___________session 2(sql 2008)
Sql server  ___________session 2(sql 2008)Sql server  ___________session 2(sql 2008)
Sql server ___________session 2(sql 2008)
Ehtisham Ali
 
The Ring programming language version 1.7 book - Part 31 of 196
The Ring programming language version 1.7 book - Part 31 of 196The Ring programming language version 1.7 book - Part 31 of 196
The Ring programming language version 1.7 book - Part 31 of 196
Mahmoud Samir Fayed
 
Cassandra v3.0 at Rakuten meet-up on 12/2/2015
Cassandra v3.0 at Rakuten meet-up on 12/2/2015Cassandra v3.0 at Rakuten meet-up on 12/2/2015
Cassandra v3.0 at Rakuten meet-up on 12/2/2015
datastaxjp
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
Andrej Pashchenko
 

Similar to Top5 functions sql2012 (20)

TSQL Functions (SQL Server)
TSQL Functions (SQL Server)TSQL Functions (SQL Server)
TSQL Functions (SQL Server)
 
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
 
New Features of SQL Server 2016
New Features of SQL Server 2016New Features of SQL Server 2016
New Features of SQL Server 2016
 
Developers' New features of Sql server express 2012
Developers' New features of Sql server express 2012Developers' New features of Sql server express 2012
Developers' New features of Sql server express 2012
 
SQL Server part 1 (6).pptx
SQL Server part 1 (6).pptxSQL Server part 1 (6).pptx
SQL Server part 1 (6).pptx
 
My Business Intelligence Portfolio
My Business Intelligence PortfolioMy Business Intelligence Portfolio
My Business Intelligence Portfolio
 
Jaime\'s Business Intelligence Portfolio
Jaime\'s Business Intelligence PortfolioJaime\'s Business Intelligence Portfolio
Jaime\'s Business Intelligence Portfolio
 
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_103 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
 
SQL Server 2008 Overview
SQL Server 2008 OverviewSQL Server 2008 Overview
SQL Server 2008 Overview
 
What's New for Developers in SQL Server 2008?
What's New for Developers in SQL Server 2008?What's New for Developers in SQL Server 2008?
What's New for Developers in SQL Server 2008?
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
 
MDI Training DB2 Course
MDI Training DB2 CourseMDI Training DB2 Course
MDI Training DB2 Course
 
IBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql FeaturesIBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql Features
 
Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
 
Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
 
Uncovering SQL Server query problems with execution plans - Tony Davis
Uncovering SQL Server query problems with execution plans - Tony DavisUncovering SQL Server query problems with execution plans - Tony Davis
Uncovering SQL Server query problems with execution plans - Tony Davis
 
Sql server ___________session 2(sql 2008)
Sql server  ___________session 2(sql 2008)Sql server  ___________session 2(sql 2008)
Sql server ___________session 2(sql 2008)
 
The Ring programming language version 1.7 book - Part 31 of 196
The Ring programming language version 1.7 book - Part 31 of 196The Ring programming language version 1.7 book - Part 31 of 196
The Ring programming language version 1.7 book - Part 31 of 196
 
Cassandra v3.0 at Rakuten meet-up on 12/2/2015
Cassandra v3.0 at Rakuten meet-up on 12/2/2015Cassandra v3.0 at Rakuten meet-up on 12/2/2015
Cassandra v3.0 at Rakuten meet-up on 12/2/2015
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
 

Recently uploaded

20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 

Recently uploaded (20)

20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 

Top5 functions sql2012

  • 1. Top 5 Built-in Functions (Transact-SQL) Manas Ranjan Dash @simplymanas
  • 2. Agenda Programmability Enhancements (Database Engine) select (my) top 5 * from SQL_BuiltIn_Functions **All the function described in this session are purely related to SQL2012. There is no resemblance with SQL2005 or SQL2008. Compatibility level 110
  • 3. What is today’s date? What is tomorrow’s date? SELECT GETDATE() SELECT GETDATE()+1
  • 4. Beginning of the month? SELECT CAST ( CAST (YEAR(GETDATE()) AS VARCHAR) + '-'+ CAST(MONTH(GETDATE()) AS VARCHAR) + '-'+ '01' AS DATE)
  • 5. Beginning of the month? I am from SQL 2012 SELECT CAST( CONCAT( YEAR(GETDATE()),'-', MONTH(GETDATE()),'-', '01') AS DATE)
  • 6. Display Full Name SQL SERVER 2012 SELECT SELECT CONCAT( FIRSTNAME +' ' + ISNULL(FIRSTNAME,'') +' ' + FIRSTNAME,' ', MIDDLENAME + ' ' + ISNULL(MIDDLENAME,'') + ' ' + MIDDLENAME,' ', LASTNAME AS FULLNAME AS FULLNAME ISNULL(LASTTNAME,'') LASTNAME FROM PERSON.PERSON ) AS FULLNAME FROM PERSON.PERSON
  • 7. CONCAT() Function BOL  CONCAT ( string_value1, string_value2 [, string_valueN ] )  All arguments are implicitly converted to string types and then concatenated. BACHCHAN  Null values are implicitly converted to an empty string.  If all the arguments are null, an empty string of type varchar(1) is returned. TOP 1
  • 8. Beginning of the month? SQL SELECT CAST ( SERVER 2012 CONCAT SELECT ( DATEFROMPARTS ( YEAR(GETDATE()),'-', YEAR(GETDATE()), MONTH(GETDATE()),'-', MONTH(GETDATE()), '01' 1) ) AS DATE)
  • 9. DATEFROMPARTS() Function BOL  DATEFROMPARTS ( year, month, day )  DATEFROMPARTS returns a date value with the date portion BACHCHAN set to the specified year, month and day. TOP 2
  • 10. End of the month? SELECT DATEADD SQL SELECT DATEADD (D,-1, SERVER (D,-1, DATEADD 2012 DATEFROMPARTS( SELECT CASE WHEN MONTH(GETDATE())<12 DATEFROMPARTS( (D,-1, YEAR(GETDATE()) THEN DECEMBER IIF(MONTH(GETDATE())<12, DATEFROMPARTS(YEAR(GETDATE()), ELSE YEAR(GETDATE())+1 YEAR(GETDATE()),YEAR(GETDATE()+1)), END, MONTH(GETDATE())+1,1) MONTH(GETDATE())+1), IIF(MONTH(GETDATE())=12,1, CASE WHEN MONTH(GETDATE())=12 THEN 1 ) 1) ELSE MONTH(GETDATE())+1 ) END, 1) )
  • 11. IIF() Function BOL  IIF ( boolean_expression, true_value, false_value)  IIF is translated into CASE BACHCHAN  IIF statements can also be nested only up to the maximum level of 10 like CASE. TOP 3
  • 12. End of the month? SQL --THIS MONTH SERVER END SELECT DATEADD SELECT EOMONTH(GETDATE()) 2012 (D,-1, --NEXT MONTH END DATEFROMPARTS( SELECT EOMONTH(GETDATE(),1) IIF(MONTH(GETDATE())<12, SELECT EOMONTH(GETDATE(),2) YEAR(GETDATE()),YEAR(GETDATE()+1)), SELECT EOMONTH(GETDATE(),14) IIF(MONTH(GETDATE())=12,1, MONTH(GETDATE())+1), --PREVIOUS MONTH END 1) SELECT EOMONTH(GETDATE(),-1) ) SELECT EOMONTH(GETDATE(),-2) SELECT EOMONTH(GETDATE(),-14)
  • 13. EOMONTH() Function BOL  EOMONTH ( start_date [, month_to_add ] )  Even if you pass a string parameter you will get a date return type as it does a implicit conversion. BACHCHAN DECLARE @date VARCHAR(255) SET @date = '12/1/2011' SELECT EOMONTH ( @date ) AS Result GO TOP 4
  • 14. Lets Format a Date SELECT CONVERT(VARCHAR, GETDATE(), 101) --11/23/2012 SELECT CONVERT(VARCHAR, GETDATE(), 102) --2012.11.23 SELECT CONVERT(VARCHAR, GETDATE(), 103) --23/11/2012 SQL SELECT CONVERT(VARCHAR, GETDATE(), 104) --23.11.2012 SERVER SELECT CONVERT(VARCHAR, 2012 GETDATE(), 105) --23-11-2012 SELECT CONVERT(VARCHAR, GETDATE(), 108) --10:04:52 SELECT FORMAT( GETDATE(), 'yyyy-MM-dd HH:MM') --2012-11-23 10:11 SELECT FORMAT( GETDATE(),' "First SQLUG Meet On" ddd dd"th" MMMM yyyy "at" HH:MM ') -- First SQLUG Meet On Fri 24th November 2012 at 10:11
  • 15. FORMAT() Function BOL  FORMAT ( value, format [, culture ] ) BACHCHAN  Use the FORMAT function for locale-aware formatting of date/time and number values as strings. For general data type conversions, use CAST or CONVERT. TOP 5
  • 16. CULTURE  You can use the SET LANGUAGE statement.  Culture accepts any culture supported by the .NET Framework as an argument;  it is not limited to the languages explicitly supported by SQL Server DECLARE @d DATETIME = '01/01/2011'; SELECT FORMAT ( @d, 'd', 'en-US' ) AS 'US English Result' ,FORMAT ( @d, 'd', 'en-gb' ) AS 'Great Britain English Result' ,FORMAT ( @d, 'd', 'de-de' ) AS 'German Result' ,FORMAT ( @d, 'd', 'zh-cn' ) AS 'Simplified Chinese (PRC) Result';
  • 17. NEWLY ADDED FUNCTIONS Conversion functions PARSE () TRY_CONVERT () TRY_PARSE () Date and time functions DATEFROMPARTS () DATETIME2FROMPARTS () Logical functions DATETIMEFROMPARTS () CHOOSE () DATETIMEOFFSETFROMPARTS () IIF () The existing LOG (Transact- EOMONTH () String functions SQL) function now has an SMALLDATETIMEFROMPARTS () CONCAT () optional second base parameter. TIMEFROMPARTS () FORMAT () LOG ( float_expression [, base ] )
  • 18. Q&A Best Reference: Books Online http://msdn.microsoft.com/en-us/library/bb510741.aspx
  • 19. simplymanas@gmail.com @simplymanas
  • 20. Inspired by Vinod Kumar, Jacob Sebastian, Pinal Dave