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
 SQL Server Development (2000)
 Best way to create records and insert into table

Author  Topic 

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2006-07-19 : 14:31:08
I need to create a table in a stored procedure that has all dates incremented by 1 week between a start date and today. This is done because I am builing a system with recurring billing for weekly,monthly,yearly,etc. For each Customer I need to make sure to bill them for the next incremented billing period. I decided to have a table that does nothing besides keep track of the customers billing dates.

Basically I want to say --


Declare @Date datetime,@StartDate datetime ,@EndDate Datetime,@CustID int
set CustID = 1
set @Startdate = cast('01/01/2000' as datetime)
set @Enddate = Getdate()
Set @Date = @StartDate

while @Date <= @EndDate
Begin
insert into #Table(Customer,Date)
Value(@CustID,@Date)

@Date = DateAdd(week,1,@Date)
End

---
and do the same for monthly,yearly,etc.
Is this the best way to do that, I need to do this for a lot of differant records, so I need to approach this the most efficiant way. Do I have any other options?

Thanks

Also this is likly a very easy question, but if I wanted to set 3 variables at one time of a query, how would I do that.

For a single item I can do

set @variable1 = Select a from Table1
or
Select @Variable1 = Select a from table1

but what if I wanted to set 3

Select @Variable1,@Variable2,@Variable3 = Select a,b,c from Table1

Will this work?

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-07-19 : 15:14:13
>> but what if I wanted to set 3

declare @a varchar(3), @b varchar(30)
Select @a = Code, @b = [Name] from table1
Print @a
Print @b


Srinika
Go to Top of Page
   

- Advertisement -