Archive

Posts Tagged ‘Geekepisodes’

Datetime Functions in SQL Server and Datepart Abbreviations

November 15th, 2010 admin No comments

You can use the datetime functions in SQL Server to manipulate the datetime values. You can either use arithmetic operations on datetime or parse datetime values.  The following list contains the datetimefunctions in SQL Server with examples

Function Name Parameters Description Example O/P
Dateadd (datepart,Number,Date) Adds the number of dateparts to the date Select dateadd(yy,2,’01/25/2000′)    1/25/2002
datediff (datepart, date1, date2) Calculates the number of dateparts between two dates Select Datediff(d,’01/25/2000′,’01/30/2000′) 5
DateName (datepart, date) Returns the datepart from the listed date ( ex: december) Select DATENAME(Month,’01/25/2000′)  January
Getdate () Returns current date time Select Getdate()  
day (date) Returns an integer , represents the day Select Day(’01/25/2000′) 25
Getutcdate () Returns the current date from the system in Universal time coordinate(UTC) time Select Getutcdate()  
Month (date) Retuns the month as integer Select Month(’01/25/2000′) 1
Year (date) Returns an integer , representing the year Select Year(’01/25/2000′) 2000

 

SQL server provides the following list of abbreviations for datepart functions

Read more…

what does NULLIF() do ? how is it different from ISNULL()?

September 14th, 2010 admin No comments

NULLIF( ) : Returns a null value if the two expressions specified in the function are equal.

The syntax used is

NULLIF ( expression1 ,expression2 )

If expression1 = expression2, then the function will return NULL.

ISNULL( ): The function replaces a null expressions with a specified value.

The syntax used is

Read more…