Tuesday, July 10, 2012

Sqlserver 2012:Details about New T-SQL commands

In sqlserver 2012 come up with three new T-SQL commands.Those are TRY_CONVERT(),OFFSET / FETCH,FORMAT().

Detailed Description with Examples:
TRY_CONVERT():
The main advantage of using this command is  we can return NULL values with out exception even if the data type does not match in column.In previous versions when we try to get the numbers as char or chars to numbers we used to get exception.
SELECT TRY_CONVERT(INT,age) from table where ISNUMERIC(age) = 25;

OFFSET / FETCH:
The main thing here is to avoid fetching the entire data from table instead it only provides us up to the required limit.Previously this option is only available in MYSQL
SELECT * FROM emp ORDER BY name OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY;

FORMAT():
BY using this string function we can show the output in desired format.Here i have a simple example to get the money format
SELECT FORMAT(12345.00,‘c’,‘en-us’);

output:12,345.00

No comments:

Bel