I am using SQL Server 2005.
I have a rate_category and an item_rate table. They are joined by the rate_cat field in each. The rate_category table contains unique rate_cat (varchar(12) and description (varchar(40)) fields for each record. I have two new items whose item_id (integer)values are 100078 and 100082. For each rate_cat that does NOT have a description LIKE 'UNUSABLE%', I want to add a record to the item_rate table with that rate_cat and one of the new item ids.
I've done a query to identify all rate_cat that don't have a description of 'UNUSABLE%'and 514 rows are returned.
select rate_cat
from rate_cat
where not description like 'UNUSABLE%'
I need a way to loop through each of the 514 rate_cat and insert a new record into the item_rate table for each item. When I'm finished, I would have added 1028 records to the item_rate table.
Here is an example
Rate_cat Table
Rate_Cat Description
A1234 Acme
A2345 Lowes
A3456 Home Depoe
A4567 Ace
A5678 True Value
A6789 UNUSABLE
Item_Rate Table
Rate_Cat Item_id Createdby
A1234 1000078 DLW
A2345 1000078 DLW
A3456 1000078 DLW
A4567 1000078 DLW
A5678 1000078 DLW
A1234 1000082 DLW
A2345 1000082 DLW
A3456 1000082 DLW
A4567 1000082 DLW
A5678 1000082 DLW
I'm not sure how to accomplish this. Thinking some kind of For Loop. Any help would be greatly appreciated.
Thanks
I have a rate_category and an item_rate table. They are joined by the rate_cat field in each. The rate_category table contains unique rate_cat (varchar(12) and description (varchar(40)) fields for each record. I have two new items whose item_id (integer)values are 100078 and 100082. For each rate_cat that does NOT have a description LIKE 'UNUSABLE%', I want to add a record to the item_rate table with that rate_cat and one of the new item ids.
I've done a query to identify all rate_cat that don't have a description of 'UNUSABLE%'and 514 rows are returned.
select rate_cat
from rate_cat
where not description like 'UNUSABLE%'
I need a way to loop through each of the 514 rate_cat and insert a new record into the item_rate table for each item. When I'm finished, I would have added 1028 records to the item_rate table.
Here is an example
Rate_cat Table
Rate_Cat Description
A1234 Acme
A2345 Lowes
A3456 Home Depoe
A4567 Ace
A5678 True Value
A6789 UNUSABLE
Item_Rate Table
Rate_Cat Item_id Createdby
A1234 1000078 DLW
A2345 1000078 DLW
A3456 1000078 DLW
A4567 1000078 DLW
A5678 1000078 DLW
A1234 1000082 DLW
A2345 1000082 DLW
A3456 1000082 DLW
A4567 1000082 DLW
A5678 1000082 DLW
I'm not sure how to accomplish this. Thinking some kind of For Loop. Any help would be greatly appreciated.
Thanks