You are here:   Home
Register  |  Login
image
 RSS Subscribe
Minimize
 Blog Calendar
Minimize
 Share This
Minimize
 Captured Technology - Blog
Minimize
Jun 22

Written by: Steve Patterson
6/22/2009 4:26 PM  RssIcon

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

Tags:
Categories:

1 comment(s) so far...


Gravatar

photoarte.fr

excellent... merci

By photoarte.fr on   8/21/2009 7:21 AM

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 
 Blog Directory
Minimize
 Mobile Version
Minimize
Add CapturedTech - Technology Mippin widget
 Translate
Minimize
 Sponsors
Minimize

u comment, i follow