CapturedTech.com

Captured Technology

Selecting the Top 2 Meeting Dates from Separate Records

Jun 22 2009

Selecting the Top 2 Meeting Dates from Separate Records

I wrote this short SQL Server code today to select the top 2 meeting dates and combine them into a single record. Using a temporary table it was possible to select the first date as one column and then select the second date as a second column. These records will be placed into a grid with the first record representing meeting dates and the second record showing agendas. Therefore the Union All was used to duplicate the first record.

--Drop Table #TempTable 

Select Top 2 meeting_date
Into  #TempTable 
From meeting_dates_table
Where published_date <= getdate()
Order By meeting_date Desc

Select (Select Top 1 meeting_date From #TempTable) As date1, (Select Top 1  meeting_date From #TempTable Order By meeting_date Asc) As date2
Union All
Select (Select Top 1 meeting_date From #TempTable) As date1, (Select Top 1  meeting_date From #TempTable Order By meeting_date Asc) As date2

Blog Directory

Latest technology news.
 Patrick Stevens
 557  246510  12/25/2024

FaceBook

Translate