I'm not sure if this is possible or not - I might be hoping for magic
I have a database that receives new records every morning. I'd like to update a companion table with default information about these new records.
The database tracks legislation - every morning, after the new bills have been added to the database, I want to update a table that tracks legislator support for a particular bill (Leg_Decision). The Leg_Decision table needs one record for every legislator for every bill. (There are 90 legislators; there should be 90 records for every bill) The table should be updated with the default value for "undecided" about supporting a bill.
Right now, the task is scripted with ColdFusion, but it's slow and I'm thinking (hoping) if there's a way to do it with straight SQL it might be faster.
Currently, I start by getting all the new bill versions (queryname- getNewKeys):
SELECT Comp_Key
FROM Measures
WHERE NOT EXISTS
(SELECT *
FROM Leg_Decision
WHERE Measures.Comp_Key = Leg_Decision.comp_key)
(is this the right query? I have a nagging feeling this query is problematic)
Then I loop through the list of comp_keys, with a nested loop of the distinct legislator IDs and insert the 90 records for each bill via:
INSERT INTO Leg_Decision (legID, comp_key, decisionID)
VALUES (#legID#, '#getNewKeys.comp_key#', 3)
There has got to be a better way. Right? Is there?
Thanks in advance.
I have a database that receives new records every morning. I'd like to update a companion table with default information about these new records.
The database tracks legislation - every morning, after the new bills have been added to the database, I want to update a table that tracks legislator support for a particular bill (Leg_Decision). The Leg_Decision table needs one record for every legislator for every bill. (There are 90 legislators; there should be 90 records for every bill) The table should be updated with the default value for "undecided" about supporting a bill.
Right now, the task is scripted with ColdFusion, but it's slow and I'm thinking (hoping) if there's a way to do it with straight SQL it might be faster.
Currently, I start by getting all the new bill versions (queryname- getNewKeys):
SELECT Comp_Key
FROM Measures
WHERE NOT EXISTS
(SELECT *
FROM Leg_Decision
WHERE Measures.Comp_Key = Leg_Decision.comp_key)
(is this the right query? I have a nagging feeling this query is problematic)
Then I loop through the list of comp_keys, with a nested loop of the distinct legislator IDs and insert the 90 records for each bill via:
INSERT INTO Leg_Decision (legID, comp_key, decisionID)
VALUES (#legID#, '#getNewKeys.comp_key#', 3)
There has got to be a better way. Right? Is there?
Thanks in advance.