User Profile

Collapse

Profile Sidebar

Collapse
deveshakgec
deveshakgec
Last Activity: Nov 15 '13, 02:23 PM
Joined: Nov 11 '13
Location: Delhi, INDA
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Hello,

    I will take care from next time.
    See more | Go to post

    Leave a comment:


  • Ways to Find and Deleting Dupliacte records IN SQL SERVER ?

    Ways to Find and Deleting Dupliacte records IN SQL SERVER
    I have solution here...

    Consider table emp
    Column: ID,C1,C2


    1) WE ARE CONSIDER IF ID AS IDENTITY COLUMN
    Code:
    DELETE FROM EMP WHERE ID NOT IN (SELECT MAX(ID) FROM EMP GROUP BY C1 ,C2)

    2) USING ROW_NUMBER()



    Consider table emp
    Column: ID,name

    Code:
    DELETE EMP_T FROM (SELECT ROW_NUMBER() OVER PARTATION
    ...
    See more | Go to post
    Last edited by Rabbit; Nov 13 '13, 04:46 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.

  • Approach 1 using DENSE_RANK()


    Consider following details
    table: Emp
    Column: name, Salary


    Code:
    (SELECT name , salary , DENSE_RANK() over (order by salary desc) AS Rowno FROM emp) a 
    Where a.Rowno=3
    Above example is for getting third largest salary.


    Appraoch 2: using subquery


    Code:
    SELECT MIN(Salary) from EMP where salary in 
    (SELECT TOP
    ...
    See more | Go to post
    Last edited by Rabbit; Nov 13 '13, 04:37 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.

    Leave a comment:


  • Ways to get N th largest salary in SQLSERVER

    Approach 1 using DENSE_RANK()


    Consider following details
    table: Emp
    Column: name, Salary


    Code:
    (SELECT name , salary , DENSE_RANK() over (order by salary desc) AS Rowno FROM emp) a 
    Where a.Rowno=3
    Above example is for getting third largest salary.


    Appraoch 2: using subquery

    Code:
    SELECT MIN(Salary) from EMP where salary in 
    (SELECT TOP 3 salary
    ...
    See more | Go to post
    Last edited by Rabbit; Nov 13 '13, 04:44 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.

  • Select top records without using TOP keyword

    Here we are using CTE

    Code:
    WITH CTE AS (
       SELECT Col1, rowno = row_number() OVER(ORDER BY Col2)
       FROM Table
       
    )
    SELECT *
    FROM   CTE
    WHERE  rowno BETWEEN 1 AND 5
    See more | Go to post
    Last edited by Rabbit; Nov 13 '13, 04:39 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
No activity results to display
Show More
Working...