Hi guys,
This is my first post out here. I read the guidelines, did not find anything relevant via searching, so I would like some help here.
I am trying to write an update statement on a table based on fields from two other tables to a third joined table.
Table 1 has a field part code and a primary key (T1.partcode, T1.1PK)
Table 2 has a field warehouse code and a primary key (T2.whcode, T2.2PK)
Table 3 hold unique information joining table 1 and table 2, so it looks like this:
T3.partcode-whcode with foreign keys indicating the record relationship to T1 and T2. Here's what I have:
[code=oracle]
UPDATE table3
SET partcode-whcode = T1.partcode || '-' || T2.whcode
FROM T1, T2, T3
WHERE T2.2PK = T3.T2FK AND T3.T1FK = T1.1PK AND
partcode-whcode <> T1.partcode || '-' || T2.whcode[/code]
On SQL Server this would work (with diff CONC method) because the FROM clause is acceptable, but Oracle doesn't use it and I'm sure there's a better way anyways, but I am just out of ideas and searching has not come up positive.
There's probably also a better way to do my join as well instead of in the WHERE clause. Any help is appreciated. If any other information is required, just ask! I am relatively new (untrained) in the SQL world, but I learn quick and retain knowledge well!!
-Derek
This is my first post out here. I read the guidelines, did not find anything relevant via searching, so I would like some help here.
I am trying to write an update statement on a table based on fields from two other tables to a third joined table.
Table 1 has a field part code and a primary key (T1.partcode, T1.1PK)
Table 2 has a field warehouse code and a primary key (T2.whcode, T2.2PK)
Table 3 hold unique information joining table 1 and table 2, so it looks like this:
T3.partcode-whcode with foreign keys indicating the record relationship to T1 and T2. Here's what I have:
[code=oracle]
UPDATE table3
SET partcode-whcode = T1.partcode || '-' || T2.whcode
FROM T1, T2, T3
WHERE T2.2PK = T3.T2FK AND T3.T1FK = T1.1PK AND
partcode-whcode <> T1.partcode || '-' || T2.whcode[/code]
On SQL Server this would work (with diff CONC method) because the FROM clause is acceptable, but Oracle doesn't use it and I'm sure there's a better way anyways, but I am just out of ideas and searching has not come up positive.
There's probably also a better way to do my join as well instead of in the WHERE clause. Any help is appreciated. If any other information is required, just ask! I am relatively new (untrained) in the SQL world, but I learn quick and retain knowledge well!!
-Derek
Comment