Subject | Newbie: SELECT works OK, but in an SP returns a NULL |
---|---|
Author | Bhavbhuti Nathwani |
Post date | 2007-11-23T07:09:30Z |
Hi all
The following SELECT works for me and returns the strings:
SELECT sJV.iAcctID, 'Accounts J.V. no. ' || CASE WHEN tJV.cBK
= '' THEN '' ELSE TRIM(tJV.cBK)
|| '/' END || TRIM(CAST(iNo AS CHARACTER(10))) || '
dtd. ' || CAST(tDt AS DATE)
|| '. ' || sJV.mRemarks
FROM tAccountsJV tJV
JOIN sAccountsJVDrCr sJV
ON sJV.iPID = tJV.iID
The same SELECT as an SP returns only NULLs:
SET TERM ^ ;
CREATE PROCEDURE NARRACCTJV (
TIID Integer )
RETURNS (
IID Integer,
MNARRATION Varchar(5000) )
AS
BEGIN
FOR
SELECT sJV.iAcctID, 'Accounts J.V. no. ' || CASE WHEN tJV.cBK
= '' THEN '' ELSE TRIM(tJV.cBK)
|| '/' END || TRIM(CAST(iNo AS CHARACTER(10))) || '
dtd. ' || CAST(tDt AS DATE)
|| '. ' || sJV.mRemarks
FROM tAccountsJV tJV
JOIN sAccountsJVDrCr sJV
ON sJV.iPID = tJV.iID
WHERE tJV.iID = :tiID
INTO :iID, :mNarration
DO
SUSPEND;
END^
SET TERM ; ^
This is the calling SELECT:
SELECT 1 AS iOrder, sJV.iID AS iPID, tJV.iID as iGID, tJV.tDt AS tDt,
sJV.iAcctID AS iAcctID, sJV.bDrAmt AS bDebit, sJV.bCrAmt AS
bCredit, 'O' AS cSource,
NarrAcctJV.mNarration AS mNarration
FROM tAccountsJV tJV
JOIN sAccountsJVDrCr sJV
ON sJV.iPID = tJV.iID
LEFT JOIN NarrAcctJV(tJV.iID)
ON NarrAcctJV.iID = tJV.iID
WHERE tJV.tDt BETWEEN '2007-10-01' AND '2007-10-31'
Please advise.
Thanks and regards
Bhavbhuti
The following SELECT works for me and returns the strings:
SELECT sJV.iAcctID, 'Accounts J.V. no. ' || CASE WHEN tJV.cBK
= '' THEN '' ELSE TRIM(tJV.cBK)
|| '/' END || TRIM(CAST(iNo AS CHARACTER(10))) || '
dtd. ' || CAST(tDt AS DATE)
|| '. ' || sJV.mRemarks
FROM tAccountsJV tJV
JOIN sAccountsJVDrCr sJV
ON sJV.iPID = tJV.iID
The same SELECT as an SP returns only NULLs:
SET TERM ^ ;
CREATE PROCEDURE NARRACCTJV (
TIID Integer )
RETURNS (
IID Integer,
MNARRATION Varchar(5000) )
AS
BEGIN
FOR
SELECT sJV.iAcctID, 'Accounts J.V. no. ' || CASE WHEN tJV.cBK
= '' THEN '' ELSE TRIM(tJV.cBK)
|| '/' END || TRIM(CAST(iNo AS CHARACTER(10))) || '
dtd. ' || CAST(tDt AS DATE)
|| '. ' || sJV.mRemarks
FROM tAccountsJV tJV
JOIN sAccountsJVDrCr sJV
ON sJV.iPID = tJV.iID
WHERE tJV.iID = :tiID
INTO :iID, :mNarration
DO
SUSPEND;
END^
SET TERM ; ^
This is the calling SELECT:
SELECT 1 AS iOrder, sJV.iID AS iPID, tJV.iID as iGID, tJV.tDt AS tDt,
sJV.iAcctID AS iAcctID, sJV.bDrAmt AS bDebit, sJV.bCrAmt AS
bCredit, 'O' AS cSource,
NarrAcctJV.mNarration AS mNarration
FROM tAccountsJV tJV
JOIN sAccountsJVDrCr sJV
ON sJV.iPID = tJV.iID
LEFT JOIN NarrAcctJV(tJV.iID)
ON NarrAcctJV.iID = tJV.iID
WHERE tJV.tDt BETWEEN '2007-10-01' AND '2007-10-31'
Please advise.
Thanks and regards
Bhavbhuti