Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
markj11
Starting Member
17 Posts |
Posted - 2008-10-16 : 13:25:06
|
I have 3 dates in the table:08/01/200809/01/200810/01/2008I pass in the dates 08/01/2008 and 11/01/2008.How do I return 09/01/2008?This is the current code which is incorrect:select top 1 date from table where date >= '08/01/2008' and date < '11/01/2008' order by date desc |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-16 : 13:32:46
|
| [code]select date from(select date,row_number() over (order by date) as seq,count(date) over() as total from table where date >= '08/01/2008'and date < '11/01/2008')twhere seq=cieling(total/2.0)[/code] |
 |
|
|
markj11
Starting Member
17 Posts |
Posted - 2008-10-16 : 13:44:48
|
| Thanks, I should have posted in 2000 since we have still have to support it.CEILING |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-16 : 13:52:15
|
try this if using sql 2000CREATE TABLE #Temp(ID int identity(1,1),date datetime)INSERT INTO #Temp (date)select datefrom table where date >= '08/01/2008'and date < '11/01/2008'order by dateSELECT t.*FROM #Temp tCROSS JOIN (SELECT COUNT(*) AS reccnt FROM #Temp)t1WHERE t.ID=CIELING(t1.recnt/2.0) |
 |
|
|
|
|
|