Subject | Re: [ib-support] SQL Question |
---|---|
Author | R. Tulloch |
Post date | 2002-06-05T14:40:23Z |
Hi:
Thanks.
Few questions:
Why does this need two instances of Mempay2?
What does SELECT 1 mean at <--- below?
over and
over for many different things. Why is an SP, "the safe route"?
//Create the update statement
IBReportQuery->SQL->Add("UPDATE MEMPAY2 M2 ");
IBReportQuery->SQL->Add("SET M2.REMIND_LET = :InvoiceDate, M2.ID
= ");
IBReportQuery->SQL->Add("(SELECT M.ID FROM MEMBERS M ");
IBReportQuery->SQL->Add(" WHERE (M.ID = M2.ID AND M.RENEW_DTE =
M2.RENEW_DATE AND ");
IBReportQuery->SQL->Add("(M.STATUS_MEM = \'ACTIVE\' OR
M.STATUS_MEM = \'ASSOCIATE\')))");
IBReportQuery->SQL->Add("WHERE (M2.RENEW_DATE IS NOT NULL AND
M2.DATE_PAID IS NULL AND ");
IBReportQuery->SQL->Add("M2.REMIND_LET IS NULL AND ");
sprintf(SQLStatement, "M2.RENEW_DATE >= %s AND M2.RENEW_DATE <=
%s)", LookBackDate.c_str(), LookAheadDate.c_str());
IBReportQuery->SQL->Add(SQLStatement);
Best regards
Thanks.
Few questions:
Why does this need two instances of Mempay2?
What does SELECT 1 mean at <--- below?
> You could try this:And lastly, I am not using an SP as I use the same query component
>
> UPDATE MEMPAY2 M3
> SET M3.REMIND_LET = :InvoiceDate
> WHERE (EXISTS (SELECT 1 FROM MEMPAY2 M2 <---
> JOIN MEMBERS M ON M2.ID = M.ID
> AND M2.RENEW_DATE = M.RENEW_DTE
> WHERE M.ID = M3.ID
> AND (M.STATUS_MEM = 'ACTIVE' OR M.STATUS_MEM = 'ASSOCIATE')
> AND M2.DATE_PAID IS NULL AND
> AND M2.REMIND_LET IS NULL
> AND M2.RENEW_DATE IS NOT NULL
> AND (M2.RENEW_DATE >= '05/04/2002' AND M2.RENEW_DATE <= '07/18/2002')))
>
> ...otherwise I'd want to go the safe route and do this in a stored procedure.
over and
over for many different things. Why is an SP, "the safe route"?
//Create the update statement
IBReportQuery->SQL->Add("UPDATE MEMPAY2 M2 ");
IBReportQuery->SQL->Add("SET M2.REMIND_LET = :InvoiceDate, M2.ID
= ");
IBReportQuery->SQL->Add("(SELECT M.ID FROM MEMBERS M ");
IBReportQuery->SQL->Add(" WHERE (M.ID = M2.ID AND M.RENEW_DTE =
M2.RENEW_DATE AND ");
IBReportQuery->SQL->Add("(M.STATUS_MEM = \'ACTIVE\' OR
M.STATUS_MEM = \'ASSOCIATE\')))");
IBReportQuery->SQL->Add("WHERE (M2.RENEW_DATE IS NOT NULL AND
M2.DATE_PAID IS NULL AND ");
IBReportQuery->SQL->Add("M2.REMIND_LET IS NULL AND ");
sprintf(SQLStatement, "M2.RENEW_DATE >= %s AND M2.RENEW_DATE <=
%s)", LookBackDate.c_str(), LookAheadDate.c_str());
IBReportQuery->SQL->Add(SQLStatement);
Best regards