SELECT CONVERT(INTEGER,'123')=>123
//Note if CONVERT(INTEGER,’1A’)=> ERROR.
Converting char to decimal.
SELECT CONVERT(Decimal(9,2), '123.4')=> 123.40
String comparison for checking date equality.
SELECT * FROM Orders
WHERE CONVERT(varchar(12), OrderDate, 101)
= CONVERT(varchar(12), GETDATE(), 101)
Null-Type checking functions
ISNULL():
Determins whether or not it is null
Syntax:
ISNULL(check_expression, replacement_value)
Examples
Replacing NULL values with ZERO values
SELECT ISNULL(qty,0) AS qty
FROM Orders;
Replacing NULL values with current date.
SELECT ISNULL(OrderDate, GETDATE())
Verifying ISNULL() returns given value if varible contains null;
SELECT ISNULL(NULL,’YES’)=> YES
NULLIF()
Returns NULL if both values are equal otherwise returns first expression.
Syntax:
NULLIF(exp1,exp2);
Examples:
SELECT NULLIF(2,2)=>NULL
SELECT NULLIF(2,3)=> 2
No need expressions to have same type.
SELECT NULLIF(2,’2’) => NULL
SELECT NULLIF(2,’4’) =>2
COALESCE()
Getting first not null value from list.; returns the first Non-NULL value in a list of expressions.
It is equivalent to CASE expression but works with NULL values.
Investing Secne is the right resource to help traders find the best brokers, strategies and investment news online. We offer content marketing services, reviews, trading charts, and industry news so you can find what you're looking for quickly. Investing Secne is a portal created for traders, to help them find the best brokers and strategies online on a single platform.
Investing Secne is the right resource to help traders find the best brokers, strategies and investment news online. We offer content marketing services, reviews, trading charts, and industry news so you can find what you're looking for quickly. Investing Secne is a portal created for traders, to help them find the best brokers and strategies online on a single platform.
ReplyDelete