views:

45

answers:

2

Hi, I am issuing an UPDATE Statement on a Sybase table but I am getting the below error:

Msg 325, Level 18, State 4: Server 'dev', Line 1: Adaptive Server finds no legal query plan for this statement. If an Abstract Plan is forcing the query plan, check its correspondence to the query. If not, please contact Sybase Technical Support.

Here is my UPDATE Statement.

 Update TABLE1 SET SAMPLECOL = (
   Select
   TABLE2.SAMPLECOL
   from TABLE2
   where
   TABLE2.COMMON_ID = TABLE1.COMMON_ID
 )
 where
 TABLE1.TABLE1_ID in (
   Select
   TABLE1.TABLE1_ID
   from TABLE1
   inner join TABLE2
   on TABLE1.COMMON_ID = TABLE2.COMMON_ID
   where TABLE1.SAMPLECOL = ''
 )

Any insights will be greatly appreciated.

+1  A: 

I THINK the problem is that you are setting the column SAMPLECOL with something which could return multiple values. Try doing this and post the result back here:

Update TABLE1 SET SAMPLECOL = (
   set rowcount 1
   Select 
   TABLE2.SAMPLECOL
   from TABLE2
   where
   TABLE2.COMMON_ID = TABLE1.COMMON_ID
   set rowcount 0
 )

(this will select only one row record and your logic might not work based on this, however as far as the error you are getting I am sure is related to this). Again try it and let us know the outcome.

VoodooChild
That would be my guess too. (Except i think you mean multiple values, not columns right?) I would also suggest running the query modified as a SELECT rather than an UPDATE to see what data comes back. This would reveal whether or not the subquery was returning non-scalar.
Paul Sasik
You are right "multiple values", is corrected - Thanks!
VoodooChild
Hi, When I used the above statement, I got an errorMsg 156, Level 15, State 2:Server 'dev', Line 1:Incorrect syntax near the keyword 'top'.
Pink Angel
are you using Sybase 9 or 11?
VoodooChild
I am using Adaptive Server Enterprise/15.0.2
Pink Angel
Ok I edited my post above - however this might be a shot in the dark...as I am using rowcount in nested select. I wish I could test it out but I don't have ASE15...
VoodooChild
Set rowcount still doesn't work. I noticed that ROWCOUNT ant TOP does not work on nested Select statements. I tried using both in an ordinary SELECT statement and both of them works.
Pink Angel
well in that case, you need to look at what you are updating the column with!!! It seems like you want to put multiple values in one column which just isn't possible (doesn't matter which sql server you are using).
VoodooChild
Actually, what I want to do is update my TABLE1.SAMPLECOL with the values in TABLE2.SAMPLECOL. The common field on these 2 tables is the COMMON_ID. Problem is, TABLE2.COMMON_ID maps to several COMMON_ID in TABLE1
Pink Angel
ok. And I am guessing you want to update all of the COMMON_ID in TABLE1 with the same value of TABLE2.COMMON_ID? Am I correct? If that is the case you can always use "SELECT DISTINCT" (included in the nested SELECT CALLS)
VoodooChild
Hi, what I just did is to create a TempTable containg 2 columns: TABLE1.COL_ID and TABLE2.SAMPLE_COL. Then I tried to update TABLE1'S SAMPLE_COL column useing this statement:UPDATE TABLE1 SET SAMPLE_COL = TEMPTABLE.SAMPLECOL FROMM TABLE1, TEMPTABLE WHERE TABLE1.COL_ID = TEMPTABLE.COL_IDI did not get any error but no row has been updated either.
Pink Angel
A: 

try instead;

update TABLE1
   set SAMPLECOL = T2.SAMPLECOL
  from TABLE1 T1, TABLE2 T2
 where T1.COMMON = T2.COMMON
   and isnull(T1.SAMPLECOL, '') = ''
Burçin Yazıcı