How to output the rows from a SQL table as expanded on a day basis using a start date and end date?

Viewed 106

I am using SQL Server 2012 and I have a table named StayInfo.

It has the following structure (extract):

Name    ArrDate        DepDate       ID
A       2016-03-29     2016-04-02    100
B       2016-05-10     2016-05-12    250

I want the following output from T-SQL query:

Name    Date          ID
A       2016-03-29   100
A       2016-03-30   100 
A       2016-03-31   100
A       2016-04-01   100
A       2016-04-03   100
B       2016-05-10   250
B       2016-05-11   250
B       2016-05-12   250

The main difficulty I am facing with this is the SQL code needed to perform the split on a day basis.

3 Answers
Related