I'm trying to make an update query with a join statement. however, it keeps throwing an error of syntax I'm not really sure where am I going wrong here cause I think I have done it right.
UPDATE AlfaGood
SET ag.name = 'New text goes here'
FROM AlfaGood ag
INNER JOIN SecondAlfa ca ON ca.id = 1
AND ag.agrid = 'Thats my original text';
Please advise on the above if possible. I get an error
ORA-00933: SQL command not properly ended
saying it's missing (; | ,) before FROM
You can do this:
UPDATE AlfaGood ag
SET ag.name = 'New text goes here'
--FROM AlfaGood ag -- not an Oracle syntax
WHERE ag.agrid = 'Thats my original text'
AND ag.id = 1
AND EXISTS ( SELECT ca.id FROM SecondAlfa ca WHERE ca.id = 1 );
Related
I'm writing a proc which has the following select statement in it
SELECT expectedValue
FROM dbo.ExclusionValues ev
JOIN dbo.StagingData sd ON ev.ExpectedVale = sd.ProductMainType
AND ev.Exclusion1 = sd.CollateralType
AND ev Exclusion2 = sd.CollateralType
My issue is with Exclusion1 & Exclusion2as I need my select statement to see if sd.CollateralType is either Exclusion1 or Exclusion2 where as right now, I'm checking on both.
What is the correct syntax for doing so?
The above snippet is from a larger proc I'm adding to and I can't provide more background on it. My issue is having a way to see if sd.CollateralType equals either Exclusion1 or Exclusion2
Just use IN clause
SELECT expectedValue
FROM dbo.ExclusionValues ev
JOIN dbo.StagingData sd ON ev.ExpectedVale = sd.ProductMainType
AND sd.CollateralType in (ev.Exclusion1, ev.Exclusion2)
I´ve been trying to find the error in this statement for a few hours and can´t seem to find it.
It must have something to do with the AND connecting the two WHERE´s since when deleting the first WHERE it works:
SELECT E_AUFMASS_KOMMENTARE.FIBU_FIRMA,
E_AUFMASS_KOMMENTARE.AUFTR_NR,
E_AUFMASS_KOMMENTARE.KOMMENTAR,
AUFTR_EXT.ART_GRUPPE
FROM HHNG_AU.E_AUFMASS_KOMMENTARE
INNER JOIN HHNG_AU.AUFTR_EXT ON E_AUFMASS_KOMMENTARE.AUFTR_NR = AUFTR_EXT.AUFTR_NR
WHERE (E_AUFMASS_KOMMENTARE.AUFTR_NR = '1248823' )
AND WHERE NOT EXISTS( SELECT * FROM HHNG_AU.EX_KOMMENTARE WHERE EX_KOMMENTARE.AUFTR_NR = '1248823' )
Too many WHERE. You only need where once, then use ANDs and ORs to combine conditions:
SELECT E_AUFMASS_KOMMENTARE.FIBU_FIRMA, E_AUFMASS_KOMMENTARE.AUFTR_NR, E_AUFMASS_KOMMENTARE.KOMMENTAR, AUFTR_EXT.ART_GRUPPE FROM HHNG_AU.E_AUFMASS_KOMMENTARE INNER JOIN HHNG_AU.AUFTR_EXT ON E_AUFMASS_KOMMENTARE.AUFTR_NR = AUFTR_EXT.AUFTR_NR WHERE (E_AUFMASS_KOMMENTARE.AUFTR_NR = '1248823' ) AND NOT EXISTS( SELECT * FROM HHNG_AU.EX_KOMMENTARE WHERE EX_KOMMENTARE.AUFTR_NR = '1248823' )
i'm working on a request ,and i think i missed a clause because i having this error
ERROR at line 1:
ORA-00933: SQL command not properly ended
the request :
echo "update account_balances_t set credit_limit='51200' inner join account_t on account_t.poid_id0=account_balances_t.obj_id0 where access_code1 in (SELECT DISTINCT ACCESS_CODE1,REC_ID FROM ACCOUNT_T A, ACCOUNT_PRODUCTS_T AP WHERE A.STATUS != 10103 AND A.ACCESS_CODE1 IS NOT NULL AND A.POID_ID0 = AP.OBJ_ID0 AND AP.PRODUCT_OBJ_ID0 = (SELECT POID_ID0 FROM PRODUCT_T WHERE NAME = 'IEW - Europe Daily Plan 1')); "|sqlplus -s `whoami`/`whoami`#$ORACLE_SID
the error :
SELECT DISTINCT ACCESS_CODE1,REC_ID FROM ACCOUNT_T A, ACCOUNT_PRODUCTS_T AP WHERE A.STATUS != 10103 AND A.ACCESS_CODE1 IS NOT NULL AND A.POID_ID0 = AP.OBJ_ID0 AND AP.PRODUCT_OBJ_ID0 = (SELECT POID_ID0 FROM PRODUCT_T WHERE NAME = 'IEW - Europe Daily Plan 1'))
*
ERROR at line 1:
ORA-00933: SQL command not properly ended
You basically have this:
UPDATE account_balances_t
SET credit_limit='51200'
INNER JOIN account_t ON account_t.poid_id0=account_balances_t.obj_id0
WHERE access_code1 IN (...);
I can't find anything similar among the available syntax variations for UPDATE.
Also, you're attempting to match column access_code1 with a subquery that returns two columns.
UPDATE PEOPLE a
SET a.SURNAME = (
select b.SURNAME
from PEOPLE b
where b.NI.NO = a.NI_NUMBER
)
update account__balances_t set credit_limit='51200' inner join account_t on .....
Syntax is bad - oracle doesn't support 'inner join' here. Correct syntax is:
UPDATE table SET colum=expression [,column = expression ... ]
WHERE condition<br>
Read here: http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_10007.htm
I am attempting to update a temp table from a source table:
UPDATE #DETAIL
SET EXCD_ID, CDOR_OR_AMT, CDOR_OR_VALUE
(SELECT
CDID_ADDL_DATA_1, CDID_ADDL_DATA, CDID_VALUE_STRING
FROM
CMC_CDID_DATA CDID
WHERE
CDID.CLCL_ID = DTL.CLCL_ID AND
CDID.CDML_SEQ_NO = DTL.CDML_SEQ_NO AND
CDID_TYPE = 'NDC'
)
FROM #DETAIL DTL
WHERE DTL.CDOR_OR_ID = 'XS'
Unfortunately it complains
Incorrect syntax near ',' (on the '(SELECT' line)
Incorrect syntax near 'FROM' (the second one)
After much trial and error I pooled some help at work and we came up with this:
UPDATE #DETAIL
SET DTL.EXCD_ID = CDID.CDID_ADDL_DATA_1,
DTL.CDOR_OR_AMT = CONVERT(MONEY,CDID.CDID_ADDL_DATA),
DTL.CDOR_OR_VALUE = CDID.CDID_VALUE_STRING
FROM #DETAIL DTL
INNER JOIN
CMC_CDID_DATA CDID ON
CDID.CLCL_ID = DTL.CLCL_ID AND
CDID.CDML_SEQ_NO = DTL.CDML_SEQ_NO
WHERE DTL.CDOR_OR_ID = 'XS'
AND CDID.CDID_TYPE = 'NDC'
Which sybase seems to accept.
You have to make the update like this:
UPDATE #DETAIL
SET DTL.EXCD_ID = CDID.CDID_ADDL_DATA_1,
DTL.CDOR_OR_AMT = CDID.CDID_ADDL_DATA
DTL.CDOR_OR_VALUE = CDID.CDID_VALUE_STRING
FROM #DETAIL DTL
INNER JOIN (SELECT
CDID_ADDL_DATA_1, CDID_ADDL_DATA, CDID_VALUE_STRING
FROM
CMC_CDID_DATA ) CDID ON CDID.CLCL_ID = DTL.CLCL_ID AND
CDID.CDML_SEQ_NO = DTL.CDML_SEQ_NO AND
CDID_TYPE = 'NDC'
WHERE DTL.CDOR_OR_ID = 'XS'
Check THIS ARTICLE for more info!
I just tried this out and it worked (on Oracle)
update dstTable T
set (T.field1, T.field2, T.field3) =
(select S.value1, S.value2, S.value3
from srcTable S
where S.key = T.Key);
This, unfortunately is Oracle specific syntax.
Caveat: Note that the update above has no where clause. It updates the entire table. If the subquery return no rows then the target fields are set to NULL. Also, it's an error if the subquery returns more than one row.
I want to fire an update query , normally using groovy we do something like :
sql.executeUpdate("update MYTABLE l set field1 where l.id = ${someobj.id}")
The above works perfectly but my problem is that i dont know ahead how many parameters i need to update. So i made a function which returns the
properttoudate1 = value1 , propertytoupdate2 = value2 .. and so on..
Then i modified the above query to
sql.executeUpdate("update MYTABLE l set ${makeQueryString(propertiesToUpdate)} where l.id = ${someobj.id}")
Now it gives me the error::
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''PROPERTY1 = 1' where l.id = 'PROPERTVALUE1'' at line 1
ANY IDEAS ??
You need to tell Groovy that the fieldname is a static, and shouldnt be replaced with ? by using Sql.expand:
sql.executeUpdate("update MYTABLE l set ${Sql.expand(makeQueryString(propertiesToUpdate))} where l.id = ${someobj.id}")