Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Date Range between Start Date and EndDate Expand / Collapse
Author
Message
Posted Wednesday, January 16, 2013 1:19 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, July 25, 2013 1:45 PM
Points: 6, Visits: 10
i have a table in which i have two coulmns of StartDate and EndDate.
i want to create an another table in which i have date coulmn. and i want to select all the range between these dates in that Date coulmn.
how would this be implemented. Additionally i am using SQL Server 2008 and i am working in Visual studio 2010.
Post #1408064
Posted Wednesday, January 16, 2013 1:34 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 13,872, Visits: 9,596
It depends on the exact results you want.

One way to do that is to join the two tables:

select *
from dbo.MyTable1 as T1
inner join dbo.MyTable2 as T2
on T2.DateColumn between T1.DateColumn1 and T1.DateColumn2;



- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #1408070
Posted Thursday, January 17, 2013 10:21 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, July 25, 2013 1:45 PM
Points: 6, Visits: 10
thanks for your rply
after excuting this query i got all the table of T1.
Actually i have two table T1.
in T1 i have two coulmns StartData and EndDate.
i want the date range selected between StartData and EndDate is to available in Date coulmn in another table.
As there are many rows in T1 so each row has to have its own StartData and EndDate. So for each row i want different table to be created. As there any way to implement it.
thanks in advance.
Post #1408538
Posted Thursday, January 17, 2013 9:50 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Sunday, September 21, 2014 9:50 PM
Points: 386, Visits: 2,356
Hi,

If you can explain it a bit more with expected data it would be really helpful to answer your question ..


Thanks,
Chinna

Its the Journey which gives you Happiness not the Destination-- Dan Millman
Post #1408709
Posted Friday, January 18, 2013 7:35 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:56 PM
Points: 13,082, Visits: 12,545
Seems the OP started a new thread for this. http://www.sqlservercentral.com/Forums/Topic1408582-391-1.aspx

I provided a solution in that thread.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1408920
Posted Friday, January 18, 2013 9:48 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, July 25, 2013 1:45 PM
Points: 6, Visits: 10
thanks for your rply.
Actually i am working in visual studion 2010 and SQL Express server 2008. i created my database through SQL Express server 2008.
Now i have i have a table in which i have three coulmns.
StartDate EndDate Class
and i have an another table name as "DateTabe" which has also three coulmns
Date Class Time

i want that the date selected between StartDate and EndDate is made available in 'Date' coulmn which is in DateTable with class in 'class' coulmn.

StartDate EndDate class
10/1/12 13/1/12 A
14/1/12 17/1/12 B

Then these can be show as in DateTable as

Date class Time
10/1/12 A
11/1/12 A
12/1/12 A
13/1/12 A
14/1/12 B
15/1/12 B
16/1/12 B
17/1/12 B

Please explain in such way so that i can implement it in visual studio 2010.

Thanks in advance
Post #1408984
Posted Friday, January 18, 2013 10:01 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:56 PM
Points: 13,082, Visits: 12,545
armaandani (1/18/2013)
thanks for your rply.
Actually i am working in visual studion 2010 and SQL Express server 2008. i created my database through SQL Express server 2008.
Now i have i have a table in which i have three coulmns.
StartDate EndDate Class
and i have an another table name as "DateTabe" which has also three coulmns
Date Class Time

i want that the date selected between StartDate and EndDate is made available in 'Date' coulmn which is in DateTable with class in 'class' coulmn.

StartDate EndDate class
10/1/12 13/1/12 A
14/1/12 17/1/12 B

Then these can be show as in DateTable as

Date class Time
10/1/12 A
11/1/12 A
12/1/12 A
13/1/12 A
14/1/12 B
15/1/12 B
16/1/12 B
17/1/12 B

Please explain in such way so that i can implement it in visual studio 2010.

Thanks in advance


Try reading the response I posted in your other thread. You really need to stick with a single thread.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1408994
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse