SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Date Range between Start Date and EndDate


Date Range between Start Date and EndDate

Author
Message
armaandani
armaandani
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
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.
GSquared
GSquared
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24201 Visits: 9730
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
armaandani
armaandani
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
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.
Sri8143
Sri8143
Mr or Mrs. 500
Mr or Mrs. 500 (539 reputation)Mr or Mrs. 500 (539 reputation)Mr or Mrs. 500 (539 reputation)Mr or Mrs. 500 (539 reputation)Mr or Mrs. 500 (539 reputation)Mr or Mrs. 500 (539 reputation)Mr or Mrs. 500 (539 reputation)Mr or Mrs. 500 (539 reputation)

Group: General Forum Members
Points: 539 Visits: 2469
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
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26558 Visits: 17557
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 Modens 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)
armaandani
armaandani
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
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
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26558 Visits: 17557
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 Modens 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)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search