I need this update query to run on both SQL Server and Oracle. Our Oracle version is 10.2 if that matters. When I run the query in Oracle I get "ERROR ORA-00933: SQL command not properly ended". What do I need to do to get this to run in Oracle?
UPDATE dbo.tableUpdate
SET fieldA = tt.fieldB
FROM dbo.tableTranslate tt
WHERE
tt.fieldC = dbo.tableUpdate.fieldC
AND
tt.fieldD = dbo.tableUpdate.fieldA
AND
1 = (
SELECT COUNT(tblTrans.fieldD)
FROM dbo.tableTranslate tblTrans
WHERE
tblTrans.fieldC = dbo.tableUpdate.fieldC
AND
tblTrans.fieldD = dbo.tableUpdate.fieldA
)
The UPDATE...FROM syntax is not valid for Oracle. You will need to use a subquery, like this:
UPDATE dbo.tableUpdate t
SET t.fieldA = (SELECT tt.fieldB
FROM dbo.tableTranslate tt
WHERE tt.fieldC = t.fieldC
AND tt.fieldD = t.fieldA
)
WHERE 1 = (
SELECT COUNT(tblTrans.fieldD)
FROM dbo.tableTranslate tblTrans
WHERE tblTrans.fieldC = t.fieldC
AND tblTrans.fieldD = t.fieldA
)