Displaying date through sql query?

  • Thread starter Thread starter ravi
  • Start date Start date
R

ravi

hi friends,
can we display last ten dates from current system date using sql
query.
example todays date
19/4/2008 from this last 10 days
18/4/2008
17/4/2008
16/4/2008
'
'
'
9/4/2008
is this possible.
i dont have any table that give me dates.
i am working on SQl server.
 
Not sure what you want to do

if you have these dates in a table then its

SELECT TOP 10 mydatefield FROM mytable

if you dont then

Dim dateArr(9)
For i = 0 To -9 Step -1
dateArr(Math.Abs(i)) = DateAdd(DateInterval.Day, i,
DateAndTime.Now)
Response.Write(DateAdd(DateInterval.Day, i, DateAndTime.Now))
Response.Write("<br>")
Next
 
simple query:

with foo (d , level)
as
(
select getdate(),1
union all
select dateadd(day,-level,d), level + 1
from foo
where level < 10
)
select d
from foo


-- bruce (sqlwork.com)
 
Back
Top