I added a company_type field to the COMPANY table and deleted the
MANUFACTURER table to normalize the database. Now I need to put the
comp_id in the CAR table in place of the man_id. If the man_id in
Manufacturer = the man_id in CAR then put the comp_id value in the
field called man_id (really the comp_id of type manufacturer). So I
eliminated the need for a manufacturer table. I wrote to fix the data
but I get an error.
---query to change man_id to comp_id
update internal_car
set internal_car.man_id = internal_manufacturer_temp.comp_id
where
INTERNAL_car.man_id = internal_manufacturer_temp.man_id;
--error---
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "internal_manufacturer_temp.man_id" could
not be bound.
---
Here is my create table for manufacturer:
CREATE TABLE INTERNAL_MANUFACTURER_temp(
man_id smallint Primary key,
comp_id smallint
);
INSERT INTO INTERNAL_MANUFACTURER_temp (man_id, comp_id) VALUES
(4, 378);
INSERT INTO INTERNAL_MANUFACTURER_temp (man_id, comp_id) VALUES
(5, 415);
INSERT INTO INTERNAL_MANUFACTURER_temp (man_id, comp_id) VALUES
(6, 416);
INSERT INTO INTERNAL_MANUFACTURER_temp (man_id, comp_id) VALUES
(7, 417);
Here is my create table CAR
CREATE TABLE[INTERNAL_CAR](
[car_id]int NOT NULL identity (1,1),
[equipment_id]int default NULL,
[aar_id]int default NULL,
[build_date]datetime default NULL,
[insp_date]datetime default NULL,
[man_id]int default NULL,
[tot_weight]int default NULL,
[light_weight]int default NULL,
[load_limit]int default NULL,
[cubic_capacity]int NOT NULL default '0',
[comments]text,
[car_type]varchar(15), CHECK ( car_type IN ('for lease','managed')) ,
PRIMARY KEY (car_id),
UNique(car_id, equipment_id)
thanks,
Plamen Ratchev - 10 Jul 2008 22:02 GMT
You have to specify the source tables in the FROM clause:
UPDATE Internal_car
SET man_id = M.comp_id
FROM Internal_car AS I
JOIN Internal_manufacturer_temp AS M
ON I.man_id = M.man_id;
HTH,
Plamen Ratchev
http://www.SQLStudio.com