Showing posts with label sql server study material. Show all posts
Showing posts with label sql server study material. Show all posts

Wednesday, 20 March 2013

Use of Case in SQL Server

Written By:- Isha Malhotra
Our Website:-Tech Altum
Use of Case in SQL Server
Sometimes we need to show the data of table in different way at runtime. In this situation we can use case statement with select query.
For Example:-
Suppose we have the following table:-
Figure 1

Rank Function in SQL server


Written By:- Isha Malhotra (Software Developer)
Email:-malhotra.isha3388@gmail.com.
Note: -if you find this article helpful then kindly leave your comment

Rank Function in SQL server
SQL server also supports Some rank function also. To use the rank function you must have to assign it to Over function. In over function we give the order in which records will be Shown.

These functions are Following:-
   1.    Rank ()
This function is used to Define the rank according to the order which we set in order by clause.
For example:-
See the following records Of temp table:-

In this table there are Two records which having the same salary i.e. 1000.
Now apply the rank function on it.

Tuesday, 19 March 2013

Date function in SQL Server


Written By:- Isha Malhotra (Software Developer)
Email:-malhotra.isha3388@gmail.com.
Note: -if you find this article helpful then kindly leave your comment

Use of DATE Function in SQL Server
When we need to play with date in sql server, in that case we can use Date Function. Following are some function which I used in my project:-
     1.       Getdate()
This function returns the current date and time in format of ‘ yyyy-mm-dd hh:mm:ss’ where
Yyyy-year
mm-months
dd-date
hh-hour
mm-minutes
ss-Second
For example:-
select GETDATE();
     2.       Day(date)
This functin will return the day part from date in numeric format.
For example:-
select DAY('2013-03-20');
this query will return 20.
  3.  Year(date)
This functin will return the year part from date in numeric format.
For example:-
select year('2013-03-20');
this query will return 2013.

Use of String function in Sql Server


Use of String Function in SQL Server
SQL Server support string function which is Already defined. Following are some important string function and their uses:-
       1.       Char (ASCII code)
This function returns the The character which is equivalent to particular ASCII code which you will pass too This function.
For Example:-
Select char (66);
This function will Return B.
      2.       ASCII (Char)
This function Returns the ASCII code which is equivalent to particular char which you will Pass to this function.
For example:-
Select ASCII ('B');
this function will return 66
     3.       Len(char)
This function returns the length of string which you will pass to len function. It returns integer value.
For Example:-
select LEN('isha malhotra');
this function will return 13
  4.  Left(char, number of char)
This function will returns the number of char from left.
For example:-
select LEFT('isha malhotra',3);
this function will return ish.