× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I should probably leave this one for one of the RPG masters, but...

What is For_Read?
Is FLBHST a character data type? The you have to enclose your 470 etc. with
single quotes.

I am going to assume you are checking either sqlcode or sqlstate after EACH
SQL statement (otherwise, you're being a bad boy :))

Not to steer you away from programming this, but I think you could do this
in one UPDATE statement.

HTH, Elvis

Celebrating 11-Years of SQL Performance Excellence on IBM i, i5/OS and
OS/400
www.centerfieldtechnology.com


-----Original Message-----
Subject: My SQL Question

Fellow Midrangers,

I am attempting to find the most recent occurrance by date of one of four
history codes. I will use only the first one I get to update another file.
I have tried SELECT DISTINCT and Fetch First Row Only but I get a 26501
SQLSTT error. I removed those and instead am reading all records which
qualify and handling the file update in another manner (only updating those
which have not been previously updated). This is a one time program so
strict efficiency is not required.

When I run this through debug, instead of getting one of my four codes, I am
getting blank codes. Where am I going wrong here? When I run it
interactively, I get records with codes.

// Get `470`, `471`, `476` And `478` Account Records From History;

// Assemble Select Statement

QQS = 'Select FLBSS, FLBTDT Desc, FLBHST From FLBHREP ';



// Set Where For Selected History Codes Since 02/01/2008

QQW = 'Where FLBHST In (?, ?, ?, ?) And FLBTDT >= ? '; // Codes Since
2/1/2008


// Set Order By Sort Method

QQO = 'Order By FLBSS '; // Order By Account



// Move SQL Statements To A Single Field

QQSQL = %Trim(QQS) + ' ' + %Trim(QQW) + ' ' + %Trim(QQO) + For_Read; //
Move Statements


// Declare, Then Open Cursor

Exec SQL Prepare SQL_Stmt2 From :QQSQL; // Prepare Executable Statement

Exec SQL Declare @C2 Cursor For SQL_Stmt2; // Declare Cursor

Exec SQL Open @C2 // Open Cursor...

Using :History_Code_470, :History_Code_471,

:History_Code_476, :History_Code_478,

:Base_Date_7; // Using These Values


Any help appreciated. I must finish this by EOD. I don't want to create a
logical for this. SQL should do it.


Robert Munday



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.