I am trying to use REPLACE to substitute spaces for commas.
If I try SELECT REPLACE('1 2 3 4 5 6 7 86 9', ' ', ', '); then I get exactly what I need in a string.
However, if I try this as part of an IN statement I only get returned the first match (ie, 1)
Here is my entire query:
SELECT aa.category_id,
aa.yyyymm,
aa.cat_balance_ytd
FROM gl_view_cat_balances AS aa
WHERE aa.gl_id = '/JOB//9'
AND aa.fin_years_ago = 0
**AND aa.category_id IN (REPLACE((SELECT detail_2
FROM gl_options
WHERE option_id = 'GLREPFUNCJOB01'),' ', ', '))**
AND aa.yyyymm = (SELECT max(bb.yyyymm)
FROM gl_rep_cat_bals as bb
WHERE bb.gl_unique_id = aa.gl_unique_id
AND bb.category_id = aa.category_id
AND bb.yyyymm <= 200910);
Field detail_2 in record GLREPFUNCJOB01 contains '1 2 3 4 5 6 7 86 9'
If anyone has some helpful hints on how I can get the commas into the string and can use it in the IN I would love to hear about them.