Monday 15 October 2012

DISTINCT

Distinct statement eliminates the duplicate data in the specified column from the table.

In a table, some of the columns may contain duplicate values. Sometimes you will want to list only the different (distinct) values in a table.

The DISTINCT keyword can be used to return only distinct (different) values.
 
DISTINCT Syntax:-
 
SELECT DISTINCT <Column_Name> FROM <Table_Name>
 
DISTINCT Example:-
 
We have a table called “salestaxRate” and columns are SalesTaxRateID,  TaxType, TaxRate, Name, ModifiedDate  as shown below...


Now we want to select only the distinct values (Different Values) from the column named "TaxRate" from the table above.

We use the following SELECT statement:

SELECT DISTINCT TaxRate FROM salestaxRate

The result-set will look like this

Saturday 6 October 2012

String Functions in SQL

String Functions:-
Before we start look at the "String Functions", first we should understand what is string? and what is functions.

What is String?
In SQL, Collection of character or combination of word is called as "String". Data whichever stored using following datatype is called as string
  • Varchar
  • NVarchar
  • Text
  • Char
  • NChar
What is Functions?
Function is a set of code or procedure which will perform some specfic operation is known as functions.

What is String Functions?
The Function which is written to perform string related opearations like...
  • Findling character length
  • Searching some character from collection of texts/paragraphs
  • Replacing some character with new character
  • Spliting a word based on some delimiter
  • etc.,
Hope above explanation is helpful to understand about what is string functions
 
The following commands are the functions which are used to perform the string operations..
  • ASCII
  • NCHAR
  • SOUNDEX
  • CHAR
  • PATINDEX
  • SPACE
  • CHARINDEX
  • QUOTENAME
  • STR
  • DIFFERENCE
  • REPLACE
  • STUFF
  • LEFT
  • REPLICATE
  • SUBSTRING
  • LEN
  • REVERSE
  • UNICODE
  • LOWER
  • RIGHT
  • UPPER
  • LTRIM
  • RTRIM
Note: We will Explain about each functions in detail in further posts..