Pages

Monday, June 23, 2014

SQL Function – Len ( )

The LEN functions return the length of char. LEN calculates length using characters as defined by the input character set. LENB uses bytes instead of characters. char can be any of the data types CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The return value is of data type NUMBER. If char has data type CHAR, then the length includes all trailing blanks. If char is null, then this function returns null.

Restriction on LENB the LENB function is supported for single-byte LOBs only. It cannot be used with CLOB and NCLOB data in a multibyte character set

SQL Function Len( ) Syntax:

Sunday, June 22, 2014

SQL Function - Round ( )

ROUND returns n rounded to integer places to the right of the decimal point. If you omit integer, then n is rounded to 0 places. The argument integer can be negative to round off digits left of the decimal point.

n can be any numeric data type or any nonnumeric data type that can be implicitly converted to a numeric data type. The argument integer must be an integer. If you omit integer, then the function returns the same data type as the numeric data type of the argument. If you include integer, then the function returns NUMBER.

Monday, June 2, 2014

SQL Function - Now( )

The Now ( ) Function returns the current date and time as a value in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS format, based where the function is used, whether the function is used in a string or numeric context. The value is expressed in the current time zone of the server where the database has nested.

SQL Function NOW( ) Syntax:

SELECT NOW() FROM table_name;

SQL Function NOW( ) Example:

Saturday, May 31, 2014

SQL Function Format( )

One of the most frequently asked questions in SQL Server forums is how to format a datetime value or column into a specific date format. Do you think January 5th 2013 should be shown as 1/5/2013 or 5/1/2013? The best answer is to each their own. The FORMAT function lets you pick the style, or better yet it can be relevant to the culture of the computer running the query.

It is worth to note that the outputs of these date formats are of VARCHAR data types already and not of DATETIME data type. With this in mind, any date comparisons performed after the datetime value has been formatted are using the VARCHAR value of the date and time and not its original DATETIME value.
The FORMAT( ) function is used to format how a field is to be displayed.

SQL FORMAT( ) Syntax:

SELECT FORMAT(column_name,format) FROM table_name;

Wednesday, May 28, 2014

SQL Statement and Syntax

SQL Statement
Syntax
CREATE DATABASE
CREATE DATABASE database_name
CREATE TABLE
CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name2 data_type,
...
)
ALTER TABLE
ALTER TABLE table_name
ADD column_name datatype
or
ALTER TABLE table_name
DROP COLUMN column_name
CREATE INDEX
CREATE INDEX index_name
ON table_name (column_name)
or
CREATE UNIQUE INDEX index_name
ON table_name (column_name)