Many a times an enterprise application has its roots in smaller application developed using a small-scale backend database services. Microsoft Access is a premier Rapid Application Development tool which a rich client application using JET engine. When such application needs to be migrated to use Microsoft SQL Server engine or SQL Azure, there is a challenge in porting the code. Since MS Access database provides access to certain expression calculation and built-in functions, it may become a non-trivial exercise to MS Access based application. To assist with this, SQL Server 2012 has introduced few built-in functions, which are syntactically and semantically same as MS Access.
CHOOSE
Returns the item at the specified index from a list of values.
Usage: CHOOSE ( index, val_1, val_2 [, val_n ] )
DATEFROMPARTS
DATETIME2FROMPARTS
DATETIMEFROMPARTS
DATETIMEOFFSETFROMPARTS
TIMEFROMPARTS
SMALLDATETIMEFROMPARTS
Returns a specific date or datetime data type value for the specified year, month, and day.
Usage: DATEFROMPARTS ( year, month, day )
- DATETIME2FROMPARTS ( year, month, day, hour, minute, seconds, fractions, precision )
- TIMEFROMPARTS ( hour, minute, seconds, fractions, precision )
- DATETIMEFROMPARTS ( year, month, day, hour, minute, seconds, milliseconds )
- DATETIMEOFFSETFROMPARTS ( year, month, day, hour, minute, seconds, fractions, hour_offset, minute_offset, precision )
- SMALLDATETIMEFROMPARTS ( year, month, day, hour, minute )
EOMONTH
Returns the last day of the month that contains the specified date, with an optional offset. The offset is month (and not date). This would be a good function for many Line Of Business and reporting applications. It would be quite easy to find out what was last day of month 3 months ago or 3 months from now.
Usage: EOMONTH ( start_date [, month_to_add ] )
FORMAT
Returns a value formatted with the specified format and optional culture. Recommended use of this function is to do a location (culture) aware conversion of strings to date time data types. For general conversion, CAST and CONVERT are still preferred built-in functions.
Usage: FORMAT ( value, format [, culture ] )
This function relies on existence of CLR being installed. If CLR is not installed (and or cannot be loaded in SQL Server 2012), the call to FORMAT function will fail. Also execution of this function will load CLR within SQL Server if not already loaded.
IIF
Returns one of two values, depending on whether the Boolean expression evaluates to true or false. IIF is a shorthand way for writing a CASE statement and is internally converted as such. All the limitations of CASE statement also apply to IIF.
Usage: IIF ( boolean_expression, true_value, false_value )
TRY_CONVERT
Returns a value cast to the specified data type if the cast succeeds; otherwise, returns null. The function can return error if casting to destination data type is explicitly not allowed. For example if you try using this function to cast an INT value to XML value, it will return an error (and not just return NULL).
Usage: TRY_CONVERT ( data_type [ ( length ) ], expression [, style ] )
LOG/LOG10
LOG returns the natural logarithm of the specified float expression, and optionally takes base as input. LOG10 returns the base-10 logarithm of the specified float expression.
Usage: LOG ( float_expression [, base ] )
LOG10 ( float_expression )
CONCAT
Returns a string that is the result of concatenating two or more string values. This is simply a string concatenation function. Return type is dependent on what input types are sent. Typically, return value is of highest precedent data type. For example, multiple varchar and nvarchar of less than 4000 bytes are sent, final output is of nvarchar of 4000 bytes in size (and may be truncated). On the other hand, if at least one value is nvarchar(max) or varchar(max), the final output is of nvarchar(max) size. Note, your arguments could be of non-string data type as well as long as they can be implicitly converted to string data type.
Usage: CONCAT ( string_value1, string_value2 [, string_valueN ] )
PARSE/TRY_PARSE
Returns the result of a string expression, translated to the requested data type. PARSE function will return error if cast/translation fails, while TRY_PARSE will return null if the cast fails. This can be useful function for location (culture) aware expression calculation.
Usage: TRY_PARSE ( string_value AS data_type [ USING culture ] )
PARSE ( string_value AS data_type [ USING culture ] )
This entry was posted on Wednesday, January 23rd, 2013 at 08:30 and is filed under Technology. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


Good article ,
helped me to easily identify the some new features :)
CHOOSE,IIF .etc are familiar in .Net
Its very good for a DBP, will help us to write query quickly :)