MS SQL Server

Find Alternate Row - TSQL Query


Find Alternate Row Query

Query - 1


Select ROW_NUMBER () over (Order By MemberID) as RowID,

 * into #temptab FROM Member
 
Select * From #temptab where (rowid%2) <>0

Query - 2

Select  Identity(int,1,1) As Rowid,
        * Into #Temptab from dbo.Member
Select * from #Temptab where (rowid%2)<>0


Result




Drop table #Temptab




Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Labels: Advance T-SQL Query
Newer Post Older Post Home

Blog Archive

  • ►  2016 (12)
    • ►  October (1)
    • ►  September (1)
    • ►  July (2)
    • ►  June (4)
    • ►  March (2)
    • ►  February (2)
  • ▼  2015 (24)
    • ►  November (1)
    • ►  October (1)
    • ►  August (3)
    • ►  July (4)
    • ►  June (5)
    • ▼  April (10)
      • In Built Function in T-SQL - Reverse
      • In Built Funtion in T-SQL - Left and Right
      • In Built Function in T-SQL - Upper and Lower
      • SQL Query To Find Last Day of Previous Month
      • Find Which Version Of SQL Server You Using
      • Find Number Of Table in Database Query
      • Find Empty Table In SQL Server
      • Find Alternate Row - TSQL Query
      • Find / Remove Duplicate From Table T-SQL Query
      • Find Record From Table That Does Not Exist In Othe...

Popular Posts

  • SSRS Expression to convert Second to Hours
    Following Expression in SSRS will convert Second to Hours Minutes Second Format HH : MM : SS   =Floor(sum(Fields!Second.Value)/ 3600)...
  • Add Default Constraint GetDate() to Existing Column
    Add constraint default getdate to existing column Alter table [dbo].[Child] Add Constraint DF_Last Default Getdate() For [LastUpdate]...
  • Find Non Integer From SQL Column
    If you want to find Non-Integer from Column in SQL Server  that does not have Data Type integer , Use following SQL Query. Select *  Fr...
  • User Define Function When LTrim and RTrim not Working
    Ltrim and RTrim not always Working to remove white space from column because of the special character at end. It may be because user try to ...
  • SQL Query to Convert Multiple CSV Column to Row
    Suppose you have following kind of table that has multiple CSV and you want to convert it to Row. Want Result like :   ...
  • Find Primary Key, Foreign Key, Constrain in SQL Table
    Find Column Name, Primary Key, Foreign Key, Constrain for particular Table in Database.     SELECT distinct             ...
  • Calculated Age Column in SQL Server Using Function
    Function to Calculate Age Column based on Floor. Create FUNCTION [dbo] . [fnCalcAge] (    @DOB datetime , -- Provid...
  • Add Calculated Column Age
    Add Calculated Age Column in SQL Server through Query Alter table Child_Record Add Age AS ( datediff ( year , [BirthDate] , getdate...
  • Find / Remove Duplicate From Table T-SQL Query
    Find Duplicate Record Query Select        MemberID,        Name,     ...
  • List Of Active Trigger in Database
    Following Query use to find all Active Trigger in Database SELECT                         sysobjects . name AS TriggerName , ...

Followers

Powered by Blogger.