Displaying date through sql query?

Displaying date through sql query?

am 19.04.2008 09:28:29 von sarellaravi

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.

Re: Displaying date through sql query?

am 19.04.2008 18:51:13 von Premium Plastics

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("
")
Next



"ravi" wrote in message
news:b43b4fd4-587b-4fb2-89bd-15306c231e99@w8g2000prd.googleg roups.com...
> 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.

Re: Displaying date through sql query?

am 19.04.2008 19:21:00 von mark

"ravi" wrote in message
news:b43b4fd4-587b-4fb2-89bd-15306c231e99@w8g2000prd.googleg roups.com...

> Can we display last ten dates from current system date using an SQL
> query?
> Is this possible?
> I don't have any table that give me dates.
> I am working on SQL Server.

There are loads of ways you could do this.

The following isn't particular robust or efficient, but it should be enough
to get you started:

CREATE TABLE #tmpDates
(
dtmDate smalldatetime
)
DECLARE @i tinyint
SET @i = 0
WHILE @i < 11
BEGIN
INSERT #tmpDates VALUES(DATEADD(day, @i * -1, getdate()))
SET @i = @i + 1
END
SELECT * FROM #tmpDates ORDER BY dtmDate DESC
DROP TABLE #tmpDates


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: Displaying date through sql query?

am 20.04.2008 07:19:02 von DFS

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)



ravi wrote:
> 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.