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 2000 Forums
 Transact-SQL (2000)
 Create Row for everyday

Author  Topic 

ccrespo
Yak Posting Veteran

59 Posts

Posted - 2007-07-16 : 15:59:48
I wanted to insert into a table a row for each day of the year... how would I do that? Like it would loop until a certain date?

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-07-16 : 16:03:11
You can do it via while loop.

While @datevalue <= @TheCertainDate
Begin
-- do the insert

-- increment the param
Set @dateval = DateadD(D,1, @dateval)
end


Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-07-16 : 16:11:50
This function will produce a date table with one row for each day in whatever date range you select.

Date Table Function F_TABLE_DATE:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=61519


CODO ERGO SUM
Go to Top of Page

ccrespo
Yak Posting Veteran

59 Posts

Posted - 2007-07-17 : 09:42:09
Do I put @dateval in the insert?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-07-17 : 11:00:04
THE Crespo?

Anyway, all I would use is a numbers table and a starting date



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-07-17 : 11:48:20
quote:
Originally posted by ccrespo

Do I put @dateval in the insert?



How would I know. If you need the value you would use it. Right?

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page
   

- Advertisement -