Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 To get dates vertically

Author  Topic 

karthick.amace
Starting Member

23 Posts

Posted - 2010-08-10 : 05:36:16
Hi bros,
I need help,
How to insert the dates vertically from 1-Jul-2010 to 31-Jul-2010 in separate table by giving the condition in where clause
BETWEEN '1-Jul-2010' and '31-Jul-2010'.

Thanks
Karthick

------------------------------------------------------
"Desire makes what you wants to do"

Sachin.Nand

2937 Posts

Posted - 2010-08-10 : 05:43:51
[code]
declare @tbl as table(fromdt datetime,todt datetime)
insert into @tbl
select '1-july-2010','31-july-2010'
;with cte
as
(
select fromdt,todt,fromdt as yourdate from @tbl
union all
select t.fromdt,t.todt,dateadd(dd,1,c.yourdate)from @tbl t
inner join cte c on t.todt>=dateadd(dd,1,c.yourdate)

)


select yourdate into #temp from cte

select yourdate from #temp

drop table #temp
[/code]


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-10 : 13:45:26
also

http://visakhm.blogspot.com/2010/02/generating-calendar-table.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

karthick.amace
Starting Member

23 Posts

Posted - 2010-08-18 : 07:49:44
can anybody explain me about this...as new bie it is hard to understand

------------------------------------------------------
"Desire makes what you wants to do"
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-08-18 : 09:54:16
This won't help, but I gotta:

I thought the whole point was to get your date HORIZONTAL.

* ba-doom ching *

Thanks, I'm here all week, try the veal.
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-08-18 : 09:59:02
quote:
Originally posted by robvolk

This won't help, but I gotta:

I thought the whole point was to get your date HORIZONTAL.

* ba-doom ching *

Thanks, I'm here all week, try the veal.



ROFL
Go to Top of Page
   

- Advertisement -