Subject | Re: IN using a string from another table field |
---|---|
Author | venussoftop |
Post date | 2012-04-12T10:43:20Z |
--- In firebird-support@yahoogroups.com, Norman Dunbar <Norman@...> wrote:
SELECT tSaleinvoice.*
FROM tSaleInvoice
WHERE (CASE WHEN COALESCE('24315,24371', '') = ''
THEN ((SELECT ',' || LIST(tSI.iID) || ',' FROM tSaleInvoice tSI WHERE tSI.iBuyerID = 1583 AND CAST(tSI.tDt AS DATE) = CAST('2012-03-31' AS DATE)))
ELSE ((SELECT ',' || TRIM(cSaleInvIDs) || ',' FROM tSaleInvoiceCvrLtr WHERE iID = 993)) END)
CONTAINING ',' || TRIM(CAST(tSaleInvoice.iID AS CHAR(10))) || ','
and it seems to return the values I am expecting!!!
Kind regards
Bhavbhuti
> Convert your id to a string with leading and trailing commas.Thanks a million Norma for the idea, this is what I have now done
> Retrieve the rows required (where tSaleInvoiceCvrLtr.iID = 993).
> For each row, wrap the list of ids in a leading and trailing comma.
> Check if your string ",id," is contained within the retrieved string
> ",id,id,id,id,id,"
SELECT tSaleinvoice.*
FROM tSaleInvoice
WHERE (CASE WHEN COALESCE('24315,24371', '') = ''
THEN ((SELECT ',' || LIST(tSI.iID) || ',' FROM tSaleInvoice tSI WHERE tSI.iBuyerID = 1583 AND CAST(tSI.tDt AS DATE) = CAST('2012-03-31' AS DATE)))
ELSE ((SELECT ',' || TRIM(cSaleInvIDs) || ',' FROM tSaleInvoiceCvrLtr WHERE iID = 993)) END)
CONTAINING ',' || TRIM(CAST(tSaleInvoice.iID AS CHAR(10))) || ','
and it seems to return the values I am expecting!!!
Kind regards
Bhavbhuti