Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Sunday, April 15, 2012

NVL2 function

The NVL2 function takes three arguments: NVL2 ( arg1, arg2, arg3 ) NVL2 returns arg3 if arg1 is NULL, and arg2 if arg1 is not NULL. The NVL function allows you to perform some value substitution for NULL values while the NVL2 function allows you to implement an IF..THEN...ELSE construct based on the nullity of data. For SQL Server we can uses the CASE statement. CASE WHEN arg1 IS NOT NULL THEN arg2 ELSE arg3 END this CASE statement will return arg3 if arg1 is NULL, and arg2 if arg1 is not NULL

Monday, December 21, 2009

Find the Nth maximum salary in sql

Find N th maximum salary using rank() function

select * from(
select dense_rank() over(order by salary desc) as rank,name from employee ) as empsalary
where rank=2