Showing posts with label sqlserver 2012. Show all posts
Showing posts with label sqlserver 2012. Show all posts

Wednesday, October 10, 2012

How to convert the Date/Number to string in sql server 2012

The new version(2012) of sql server makes easy to string conversion from number or date.We don't have any direct  function to do this one in older versions .If we want to do this one ,then we have to use Conversion functions(CAST or CONVERT).
SELECT CAST(date AS nvarchar(100)) AS string_date from Orders
The FORMAT string function has introduced to convert the number/date to string in Sql server 2012 .Here i have given a simple query to get the amount(It has money data type in table)  in currency format.
SELECT order_ID,FORMAT(Price_Amt, 'C', 'en-us') AS 'Amount' from Orders
In this function we  have to use standard numeric formats for desired Format ..Details about standard Numeric Format Strings

Thursday, October 4, 2012

How to concatenate strings in sql server 2012

In previous versions there is no direct function to make this one.If we want concatenate two strings we have to use '+' symbol .
But in the latest version of sql server2012 introduce a new string function "CONCAT()" ,which is used to concatenate the strings.Let me explain one example for how to use and execute this function in sql server 2012.
Here i have table with three five columns(id,name,sal,surname,add).Now i want to concatenate the name and surname when executes the select query from emp table

select id,CONCAT(name,surname) as FullName from employee

Monday, September 3, 2012

How to get last day of the month ||End Of Month in Sqlserver 2012

In previous SQL versions we don't have any direct option to get the last day of month using current date or custom date.In Sql 2012 come up with some new built function to get End of Month value i.e EOMONTH.In this post i will given how to use this function in T-Sql.

SELECT EOMONTH ( date ) as LDM,First_Name,Addr,Country from Employee 
If we will given an input like '09/03/2012',Then the result will be like this '2012-09-30'

Wednesday, July 18, 2012

SQL Server 2012:Complete details of New functions in SSIS

In this post i will give brief explanation about new functions in SSIS.In this version we have four new functions .Those are
LEFT:In previous versions there is no LEFT option in SSIS.In this version it will introduces as one of the string function In ssis and it will be use instead of SUBSTRING function.So by using this we can get left part of string
ex:SELECT LEFT(Full name, 3) 
FROM orders
REPLACENULL:It will use to replace the null values.
ex:REPLACENULL(city, "Hyderabad")
TOKEN:By using this function we can return a substring by using delimiters to separate a string into tokens
ex:TOKEN("Bhaskar developer"," ",1) 
give result as bhaskar
TOKENCOUNT:This function will give the count of tokens in the string which is already convert to token from string using delimiters
Ex:TOKENCOUNT("My name is bhaskar"," ")
The count this token is 4

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

Bel