Domanda

I have a form where I submit a Start and End date to book of holidays, I then send the value's across to SQL, now i'm a bit stuck because what I need to do is get the dates between the start and end date.

Can anyone help me with this I just need a calculation for my select statement to transfer all the dates between and on the start and end date.

Thanks in advance to your answers/replies :)

È stato utile?

Soluzione

Try this:

DECLARE @FromDate datetime
DECLARE @ToDate datetime
SELECT @FromDate=FromDateCol FROM TableName
SELECT @ToDate=ToDateCol FROM TableName
WITH cte AS
(
  SELECT CAST(@FromDate AS DATETIME) DateValue
  UNION ALL
  SELECT  DateValue + 1
  FROM    cte   
  WHERE   DateValue + 1 < @ToDate
)

SELECT  DateValue
FROM    cte
OPTION (MAXRECURSION 0)

Altri suggerimenti

That should not be to difficult to difficult to figure if you are using SQL server! Try this website it is good documentation on how to retrieve those dates that you need.

These are the select statements: start date (PRSTDATE) and the end date (PRENDATE)

SELECT statement docs.oracle.com/javadb/10.6.2.1/.../rrefsqlj41360.htm...‎

You asked for the URL, all I have is the web address! Paste it into your search engine. I Hope it helps...

http://docs.oracle.com/javadb/10.6.2.1/ref/rrefsqlj41360.html

Hi just do a while loop,

While @Date <= @EndDate
Begin
    Set @Date = DATEADD(DD, 1, @Date)
    Select @Date
End
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top