Re:Re: Update
Stan wrote:
Quote
What is wrong with below SQL ?
UPDATE ODETAILS SET ODETAILS.COST=PARTS.COST
WHERE ODETAILS.PARTNO=PARTS.PARTNO
While the syntax is nice (i.e. I think it would be great <g>), this is not a
valid update statement because values from other tables need to be
*selected*.
UPDATE ODETAILS SET
ODETAILS.COST= (
SELECT PARTS.COST FROM PARTS
WHERE ODETAILS.PARTNO=PARTS.PARTNO
)
Note that this is a correlated subquery, it executes once for every ODETAILS
row to be updated. If you find this statement slow, it can be made much more
efficient in a stored procedure where you could do the following:
FOR
SELECT ODETAILS.PARTNO, ODETAILS.COST
FROM ODETAILS
INNER JOIN PARTS
ON ODETAILS.PARTNO=PARTS.PARTNO
INTO :PARTNO, :COST
DO BEGIN
UPDATE ODETAILS SET
ODETAILS.COST = :COST
WHERE ODETAILS.PARTNO=:PARTNO
END;
--
Wayne Niddery - Logic Fundamentals, Inc. (
www.logicfundamentals.com)
RADBooks:
www.logicfundamentals.com/RADBooks.html
"The legitimate powers of government extend to such acts only as are
injurious to others. But it does me no injury for my neighbor to say
there are twenty gods, or no God. It neither picks my pocket nor breaks
my leg." ?Thomas Jefferson