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)
 Insert query

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2005-09-29 : 09:34:33
I would appreciate some help with the following query.

I have a table, tblRB_Facilities, each record being a different piece of equipment. I have another table, tblRB_FacilitiesDates. I want to run through tblRB_Facilities and add a record to tblRB_FacilitiesDates for every piece of equipment for every day, for a year from today, the key on tblRB_FacilitiesDates being Equipmentname*Date eg PrinterHP5*29/09/05

TIA

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-29 : 09:41:08
Here is a general approach

Update T1 set T1.Col=T2.Col from tblRB_FacilitiesDates T1 inner join tblRB_Facilities T2
on T1.Equipmentname=T2.Equipmentname

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2005-09-29 : 09:50:25
I want to insert a record, not update as tblRB_FacilitiesDates is empty.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-29 : 10:03:46
Post some sample data and the result you want

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2005-09-29 : 10:25:34
tblRB_Facilites
FA_Id (autonumber key)
FA_Item (nvarchar (100)

eg 1 PrinterA
2 PrinterB
3 Laptop
4 Projector

tblRB_FacilitiesDates

FD_FaciltiesRef (Key)
FD_DateRequired (datetime)
FD_Item (nvarchar(100)
FD_P1 (bit)
FD_P2 (bit)....
FD_P28

I want

PrinterA*29/09/05
29/09/05
PrinterA
0
0...etc to field FD_BP28
this for each item in RB_Facilites and then to increment the date by 1 day and do it all again until I have a record for the next 365 days for each item.

PrinterA*30/09/05
30/09/05
PrinterA
0
0...etc to field FD_BP28

Thanks for your help




Go to Top of Page
   

- Advertisement -