Ads

Captured Technology - Blog

Selecting the Top 2 Meeting Dates from Separate Records

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
 554  246482  11/15/2024

Translate

Categories

Blog Calendar