WebFocus to DB2 conversion


I am having trouble converting the LAST function in WebFocus to DB2. The 'last' function in webfocus returns the last value returned for a column.

for example in WebFocus:
somevar/A5 = if (col_a ne last col_a) then 'AB' else 'CD'

what would be the equivalent to that in DB2?
Who is Participating?
Kent OlsenConnect With a Mentor Data Warehouse Architect / DBACommented:
Here's a really short example that I copied from elsewhere...

create procedure DEPARTMENT_SALARY
  (in v_depno varchar(3), out v_totalsalary decimal(9,2))
  declare SQLCODE  integer     default 0;
  declare i        decimal(9,2);
  declare mycur cursor for
      select SALARY
      from EMPLOYEE
      where WORKDEPT = v_depno;

  set v_totalsalary = 0;
  open mycur;
  fetch mycur into i;
  while SQLCODE <> 100
     set v_totalsalary = v_totalsalary + i;
     fetch mycur into i;
  end while;
  close mycur;
Dave FordSoftware Developer / Database AdministratorCommented:
Could you explain the LAST function a bit more? Your example doesn't appear to reference that function.
Kent OlsenData Warehouse Architect / DBACommented:
Hi Wrangler,

There isn't an equivalent in DB2.  If you're using cursors to view rows one at a time, the easiest way is to just save the column value into a "last" variable whenever you fetch another row.

CodeWranglerAuthor Commented:
Kent - yeah, im starting to think that might be the way to go about it..

Dave - note the word 'last' enclosed in the if statement. you can look up some info on it using google. Basically, if the last value of col_a matches the current value of col_a then do something.
CodeWranglerAuthor Commented:
Kent - do you have any good examples (resources) of DB2 cursors?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.