|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Update using an Inner JoinI want to update records using an inner join but cannot work out the syntax.
Can anyone help me? They way I am doing the update is thus: Update LTT.SROPRG SET (PGPLAN, PGRESP)= (Select HANDLER as HANDA, HANDLER as HANDB from LISTERDAT.HANDLER where PGPRDC = ITEM) but this way throws an error when the number of items in LISTERDAT.HANDLER is less that the number of items in LTT.SROPRG. The error message says null values not allowed I would like to do it like this: Update LTT.SROPRG SET PGPLAN = HANDLER, PGRESP = HANDLER Inner Join LISTERDAT.HANDLER on PGPRDC = ITEM but I cannot get the syntax right. Any help much appreciated Due to the lack of information about the columns that´ll be a sort of
solution, vene for the syntax: Update LTT.SROPRG SET PGPLAN = HANDLER, PGRESP = HANDLER FROM LTT.SROPRG S Inner Join LISTERDAT.HANDLER H on S.PGPRDC = H.ITEM Show quote "Billy" wrote: > I want to update records using an inner join but cannot work out the syntax. > Can anyone help me? > > They way I am doing the update is thus: > Update LTT.SROPRG SET (PGPLAN, PGRESP)= (Select HANDLER as HANDA, > HANDLER as HANDB from LISTERDAT.HANDLER where PGPRDC = ITEM) > > but this way throws an error when the number of items in LISTERDAT.HANDLER > is less that the number of items in LTT.SROPRG. The error message says null > values not allowed > > I would like to do it like this: > Update LTT.SROPRG SET PGPLAN = HANDLER, PGRESP = HANDLER Inner Join > LISTERDAT.HANDLER on PGPRDC = ITEM > > but I cannot get the syntax right. Any help much appreciated Thx for the reply.
When I try your solution, I get this error message [IBM][iSeries Access ODBC Driver][DB2 UDB]SQL0199 - Keyword FROM not expected. Valid tokens: <END-OF-STATEMENT>. Just so you know, I have posted this in here because it's a SQL statement I'm running, but I'm not using the query on a SQL Server - I'm running it against an AS400 so it might be (most probably) a limitation on the SQL syntax allowed on the AS400...should've mentioned that before, sorry. Any other ideas? Show quote "Jens Süßmeyer" wrote: > Due to the lack of information about the columns that´ll be a sort of > solution, vene for the syntax: > > > Update LTT.SROPRG SET PGPLAN = HANDLER, PGRESP = HANDLER > FROM LTT.SROPRG S Inner Join > LISTERDAT.HANDLER H on S.PGPRDC = H.ITEM > -- > HTH, Jens Suessmeyer. > > --- > http://www.sqlserver2005.de > --- > > > "Billy" wrote: > > > I want to update records using an inner join but cannot work out the syntax. > > Can anyone help me? > > > > They way I am doing the update is thus: > > Update LTT.SROPRG SET (PGPLAN, PGRESP)= (Select HANDLER as HANDA, > > HANDLER as HANDB from LISTERDAT.HANDLER where PGPRDC = ITEM) > > > > but this way throws an error when the number of items in LISTERDAT.HANDLER > > is less that the number of items in LTT.SROPRG. The error message says null > > values not allowed > > > > I would like to do it like this: > > Update LTT.SROPRG SET PGPLAN = HANDLER, PGRESP = HANDLER Inner Join > > LISTERDAT.HANDLER on PGPRDC = ITEM > > > > but I cannot get the syntax right. Any help much appreciated I have tried the UPDATE FROM syntax (a favorite of mine) against DB2 on an
AS400 and also found it not to work there. My primary reference on DB2's syntax is http://publib.boulder.ibm.com/iseries/legacy/html/as400/v4r5/ic2924/index.htm?info/db2/rbafymst02.htm Not sure what newsgroups are out there for DB2 ... Jens' answer was beautiful for MS SQL Server ... can't comment further on DB2. -- Show quoteDaniel Wilson Senior Software Solutions Developer Embtrak Development Team http://www.Embtrak.com DVBrown Company "Billy" <Bi***@discussions.microsoft.com> wrote in message news:0F09784C-CA11-4AC9-AFB2-312010A384E8@microsoft.com... > Thx for the reply. > > When I try your solution, I get this error message > > [IBM][iSeries Access ODBC Driver][DB2 UDB]SQL0199 - Keyword FROM not > expected. Valid tokens: <END-OF-STATEMENT>. > > Just so you know, I have posted this in here because it's a SQL statement > I'm running, but I'm not using the query on a SQL Server - I'm running it > against an AS400 so it might be (most probably) a limitation on the SQL > syntax allowed on the AS400...should've mentioned that before, sorry. > > Any other ideas? > > "Jens Süßmeyer" wrote: > > > Due to the lack of information about the columns that´ll be a sort of > > solution, vene for the syntax: > > > > > > Update LTT.SROPRG SET PGPLAN = HANDLER, PGRESP = HANDLER > > FROM LTT.SROPRG S Inner Join > > LISTERDAT.HANDLER H on S.PGPRDC = H.ITEM > > -- > > HTH, Jens Suessmeyer. > > > > --- > > http://www.sqlserver2005.de > > --- > > > > > > "Billy" wrote: > > > > > I want to update records using an inner join but cannot work out the syntax. > > > Can anyone help me? > > > > > > They way I am doing the update is thus: > > > Update LTT.SROPRG SET (PGPLAN, PGRESP)= (Select HANDLER as HANDA, > > > HANDLER as HANDB from LISTERDAT.HANDLER where PGPRDC = ITEM) > > > > > > but this way throws an error when the number of items in LISTERDAT.HANDLER > > > is less that the number of items in LTT.SROPRG. The error message says null > > > values not allowed > > > > > > I would like to do it like this: > > > Update LTT.SROPRG SET PGPLAN = HANDLER, PGRESP = HANDLER Inner Join > > > LISTERDAT.HANDLER on PGPRDC = ITEM > > > > > > but I cannot get the syntax right. Any help much appreciated >> I have tried the UPDATE FROM syntax (a favorite of mine) against DB2 on an AS400 and also found it not to work there. << Because DB2 follows Standards, and SQL Server does not; use a rowconstructor in DB2. The proprietary UPDATE..FROM.. can produce unpredictable results, so good programmers avoid it and bitch to MS about the lack of Standards conformance after over a decade. Thx for the reply and the link.
Show quote "Daniel Wilson" wrote: > I have tried the UPDATE FROM syntax (a favorite of mine) against DB2 on an > AS400 and also found it not to work there. > > My primary reference on DB2's syntax is > http://publib.boulder.ibm.com/iseries/legacy/html/as400/v4r5/ic2924/index.htm?info/db2/rbafymst02.htm > > Not sure what newsgroups are out there for DB2 ... Jens' answer was > beautiful for MS SQL Server ... can't comment further on DB2. > > > -- > Daniel Wilson > Senior Software Solutions Developer > Embtrak Development Team > http://www.Embtrak.com > DVBrown Company > > "Billy" <Bi***@discussions.microsoft.com> wrote in message > news:0F09784C-CA11-4AC9-AFB2-312010A384E8@microsoft.com... > > Thx for the reply. > > > > When I try your solution, I get this error message > > > > [IBM][iSeries Access ODBC Driver][DB2 UDB]SQL0199 - Keyword FROM not > > expected. Valid tokens: <END-OF-STATEMENT>. > > > > Just so you know, I have posted this in here because it's a SQL statement > > I'm running, but I'm not using the query on a SQL Server - I'm running it > > against an AS400 so it might be (most probably) a limitation on the SQL > > syntax allowed on the AS400...should've mentioned that before, sorry. > > > > Any other ideas? > > > > "Jens Süßmeyer" wrote: > > > > > Due to the lack of information about the columns that´ll be a sort of > > > solution, vene for the syntax: > > > > > > > > > Update LTT.SROPRG SET PGPLAN = HANDLER, PGRESP = HANDLER > > > FROM LTT.SROPRG S Inner Join > > > LISTERDAT.HANDLER H on S.PGPRDC = H.ITEM > > > -- > > > HTH, Jens Suessmeyer. > > > > > > --- > > > http://www.sqlserver2005.de > > > --- > > > > > > > > > "Billy" wrote: > > > > > > > I want to update records using an inner join but cannot work out the > syntax. > > > > Can anyone help me? > > > > > > > > They way I am doing the update is thus: > > > > Update LTT.SROPRG SET (PGPLAN, PGRESP)= (Select HANDLER as HANDA, > > > > HANDLER as HANDB from LISTERDAT.HANDLER where PGPRDC = ITEM) > > > > > > > > but this way throws an error when the number of items in > LISTERDAT.HANDLER > > > > is less that the number of items in LTT.SROPRG. The error message says > null > > > > values not allowed > > > > > > > > I would like to do it like this: > > > > Update LTT.SROPRG SET PGPLAN = HANDLER, PGRESP = HANDLER Inner Join > > > > LISTERDAT.HANDLER on PGPRDC = ITEM > > > > > > > > but I cannot get the syntax right. Any help much appreciated > > > On Fri, 12 Aug 2005 02:18:09 -0700, Billy wrote:
Show quote >I want to update records using an inner join but cannot work out the syntax. Hi Billy,>Can anyone help me? > >They way I am doing the update is thus: > Update LTT.SROPRG SET (PGPLAN, PGRESP)= (Select HANDLER as HANDA, >HANDLER as HANDB from LISTERDAT.HANDLER where PGPRDC = ITEM) > >but this way throws an error when the number of items in LISTERDAT.HANDLER >is less that the number of items in LTT.SROPRG. The error message says null >values not allowed > >I would like to do it like this: >Update LTT.SROPRG SET PGPLAN = HANDLER, PGRESP = HANDLER Inner Join >LISTERDAT.HANDLER on PGPRDC = ITEM > >but I cannot get the syntax right. Any help much appreciated Reading the rest of the thread, I see that you're using DB2. The proprietary Transact-SQL UPDATE FROM syntax is not supported by DB2. You might try to use one of the following: * If DB2 supports row constructors: UPDATE LTT.SROPRG SET (PGPLAN, PGRESP) = (SELECT HANDLER, HANDLER FROM LISTERDAT.HANDLER WHERE PGPRDC = ITEM) WHERE EXISTS (SELECT * FROM LISTERDAT.HANDLER WHERE PGPRDC = ITEM) (And I do hope that one of PGPRDC and ITEM is in the LTT.SROPRG table, and the other is in LISTERDAT.HANDLER). * If DB2 doesn't support row constructors: UPDATE LTT.SROPRG SET PGPLAN = (SELECT HANDLER FROM LISTERDAT.HANDLER WHERE PGPRDC = ITEM), PGPLAN = (SELECT HANDLER FROM LISTERDAT.HANDLER WHERE PGPRDC = ITEM) WHERE EXISTS (SELECT * FROM LISTERDAT.HANDLER WHERE PGPRDC = ITEM) All these untested, as I don't have your tables, your data or a DB2 installation. Best, Hugo -- (Remove _NO_ and _SPAM_ to get my e-mail address) |
|||||||||||||||||||||||