TechSapphire Sunday, 2024-12-22, 5:56 AM
Site menu
Login form
News
Play Games
  • Deep Freeze
  • Ice Slide
  • Gyroball
  • Fat Fish
  • Bush Royal Rampage
  • Main » 2012 » September » 03
    Get duplicate records from table
    Select ename from tbemp a where a.eno!=(select Max(eno) from tbemp b where a.ename=b.ename)

    Here eno denotes to employee number and ename denotes to employee name.
    Category: Database | Views: 2356 | Added by: Admin | Date: 2012-09-03 | Comments (0)

    Without Data
    Select * INTO tbem1 from tbemp where 1=2

    Why 1=2?
    Because none of the record could satisfy this condition i.e. 1=2. So no data would be copied into newly created table.

    With Data
    Select * INTO tbemp2 from tbemp

    With Condition
    Select * INTO tbemp3 from tbemp where depcod=102

    Here depcod denotes to department code.


    Category: Database | Views: 2305 | Added by: Admin | Date: 2012-09-03 | Comments (0)

    Select Alternate Row SQL Server

    Their are many approaches to get alternate record from SQL server database table. Here i have discussed 2 approaches
    1. Complex Query
    2. Using Views

    Complex Query: SELECT * from (SELECT ROW_NUMBER() OVER(ORDER BY Employee_id) as RowNumber, * from employees) T where t.RowNumber%2=0

    Using Views:
    CREATE VIEW with_rownumber
    as
    SELECT ROW_NUMBER() OVER(ORDER BY Employee_id) as RowNumber,* from employees;

    SELECT * from with_rownumber where RowNumber%2=0

    The approach preferred here is using VIEW because:
    1. Easy to understand.
    2. In future if you need to perform any operation related to RowNumber then you don't need to create another complex query. You could use view having rownumber column in it.


    Category: Database | Views: 3461 | Added by: Admin | Date: 2012-09-03 | Comments (0)

    Categories
    Programming [27]
    Tips for programming
    Security [2]
    Security Tips
    Google [1]
    Use google faster then ever you use
    Project [14]
    HTML [2]
    Electronics [0]
    Data Structure [0]
    Database [16]
    SQL SERVER
    SSRS [1]
    Sql Server Reporting Services
    Copyright MyCorp © 2024