Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL -120 Error

Status
Not open for further replies.

MikeMcKeown

Programmer
Apr 1, 2003
69
GB
I'm getting an SQL -120 error on this bit of SQL

-120 A WHERE CLAUSE, SET CLAUSE, VALUES CLAUSE, OR A SET ASSIGNMENT STATEMENT INCLUDES A COLUMN FUNCTION

EXEC SQL
SELECT ASU_NEW_NET_RATE
INTO :SMM03-ASU-NEW-NET-RATE
FROM SMM03 A
WHERE A.EFFECTIVE_DATE = MAX(A.EFFECTIVE_DATE)
END-EXEC

I just want to select the most recent row from the table.

Any help, much appreciated

Thanks in advance,
 
try
with ab as (select max(a.effective_date) max_date from smm03)
SELECT ASU_NEW_NET_RATE
INTO :SMM03-ASU-NEW-NET-RATE from smm03 a
where a.effective_date = ab.max_date

or
select aa into :variable from bb where bb.date in (select max(effective_date) from xx)

Note. I haven´t tried this, so you may need to work around it, but it should give you an idea
 
How about this max date will float to top then just check for the -811 ( more the on row in singleton select) and ignore:

Code:
EXEC SQL
   SELECT ASU_NEW_NET_RATE
   INTO  :SMM03-ASU-NEW-NET-RATE
   FROM SMM03 A
   order by A.EFFECTIVE_DATE  DESC
END-EXEC

evaluate SQLCODE
   when ZERO
   when -811
      CONTINUE   (row found)
   when +100
      display 'No row Found processing'
   when other
      perform DB2 Error Routines
end-evaluate
 
SQL questions don't belong here. Better ask this at the DB2 forum.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top