Subject | Re: [firebird-support] Newbie: SELECT works OK, but in an SP returns a NULL |
---|---|
Author | Helen Borrie |
Post date | 2007-11-23T08:04:46Z |
At 06:09 PM 23/11/2007, you wrote:
[ ...a total spaghetti dinner ... ]
Anyway, start off by putting in the qualifiers for the fields you are referring to in your expression. I'll guess them. You fix them. Then forget about joining to a stored procedure. It's a really bad idea, maybe useful once in a hundred years when you have a retrieval to do that can't be done any other way. In SQL, the simpler, the better.
CREATE VIEW Narration (
iid,
mnarration)
as
SELECT
sJV.iAcctID,
'Accounts J.V. no. ' ||
CASE WHEN tJV.cBK = '' THEN '' ELSE TRIM(tJV.cBK) || '/' END ||
TRIM(CAST(sJV.iNo AS CHARACTER(10))) || 'dtd. ' ||
CAST(sJV.tDt AS DATE) || '. ' ||
sJV.mRemarks
FROM tAccountsJV tJV
JOIN sAccountsJVDrCr sJV
ON sJV.iPID = tJV.iID;
COMMIT;
SELECT
1 AS iOrder,
sJV.iID,
tJV.iID,
tJV.tDt,
sJV.iAcctID,
sJV.bDrAmt,
sJV.bCrAmt,
'O' AS cSource,
Narr.mNarration
FROM tAccountsJV tJV
JOIN sAccountsJVDrCr sJV ON sJV.iPID = tJV.iID
LEFT JOIN Narration Narr ON Narr.iID = tJV.iID
WHERE tJV.tDt BETWEEN '2007-10-01' AND '2007-10-31'
Note that the query can be done in one, without any need to create any kind of virtual set to join to, i.e., simplified further:
SELECT
1 AS iOrder,
sJV.iID,
tJV.iID,
tJV.tDt,
sJV.iAcctID,
sJV.bDrAmt,
sJV.bCrAmt,
'O' AS cSource,
'Accounts J.V. no. ' ||
CASE WHEN tJV.cBK = '' THEN '' ELSE TRIM(tJV.cBK) || '/' END ||
TRIM(CAST(sJV.iNo AS CHARACTER(10))) || 'dtd. ' ||
CAST(sJV.tDt AS DATE) || '. ' ||
sJV.mRemarks as mNarration
FROM tAccountsJV tJV
JOIN sAccountsJVDrCr sJV ON sJV.iPID = tJV.iID
WHERE tJV.tDt BETWEEN '2007-10-01' AND '2007-10-31'
And I hope you understand the difference between inner and outer joins...
./heLen
[ ...a total spaghetti dinner ... ]
Anyway, start off by putting in the qualifiers for the fields you are referring to in your expression. I'll guess them. You fix them. Then forget about joining to a stored procedure. It's a really bad idea, maybe useful once in a hundred years when you have a retrieval to do that can't be done any other way. In SQL, the simpler, the better.
CREATE VIEW Narration (
iid,
mnarration)
as
SELECT
sJV.iAcctID,
'Accounts J.V. no. ' ||
CASE WHEN tJV.cBK = '' THEN '' ELSE TRIM(tJV.cBK) || '/' END ||
TRIM(CAST(sJV.iNo AS CHARACTER(10))) || 'dtd. ' ||
CAST(sJV.tDt AS DATE) || '. ' ||
sJV.mRemarks
FROM tAccountsJV tJV
JOIN sAccountsJVDrCr sJV
ON sJV.iPID = tJV.iID;
COMMIT;
SELECT
1 AS iOrder,
sJV.iID,
tJV.iID,
tJV.tDt,
sJV.iAcctID,
sJV.bDrAmt,
sJV.bCrAmt,
'O' AS cSource,
Narr.mNarration
FROM tAccountsJV tJV
JOIN sAccountsJVDrCr sJV ON sJV.iPID = tJV.iID
LEFT JOIN Narration Narr ON Narr.iID = tJV.iID
WHERE tJV.tDt BETWEEN '2007-10-01' AND '2007-10-31'
Note that the query can be done in one, without any need to create any kind of virtual set to join to, i.e., simplified further:
SELECT
1 AS iOrder,
sJV.iID,
tJV.iID,
tJV.tDt,
sJV.iAcctID,
sJV.bDrAmt,
sJV.bCrAmt,
'O' AS cSource,
'Accounts J.V. no. ' ||
CASE WHEN tJV.cBK = '' THEN '' ELSE TRIM(tJV.cBK) || '/' END ||
TRIM(CAST(sJV.iNo AS CHARACTER(10))) || 'dtd. ' ||
CAST(sJV.tDt AS DATE) || '. ' ||
sJV.mRemarks as mNarration
FROM tAccountsJV tJV
JOIN sAccountsJVDrCr sJV ON sJV.iPID = tJV.iID
WHERE tJV.tDt BETWEEN '2007-10-01' AND '2007-10-31'
And I hope you understand the difference between inner and outer joins...
./heLen