Hi, I have comma separated values in a variable.I want to use it in WHERE clause to filter records against a column in databse table as we do it using IN operator in Oracle. As we do not have IN in maintain, How can we achieve this requirement. E.g. Suppose variable contains value 'A,AB,ABC' . Now I have to use these values in WHERE clause as
WHERE [coumn name] eq 'A' and [coumn name] eq 'AB' and [coumn name] eq 'ABC';
There can be any number of values in variable. Please suggest a way to achive this in maintain.
Thanks in advance.This message has been edited. Last edited by: Kerry,
I am not a SQL specialist, but I wonder if this where clause would work. The column name can not be A and B and AB at the same time. I would suggest to change the AND into OR
Frank
prod: WF 7.6.10 platform Windows, databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7 test: WF 7.6.10 on the same platform and databases,IE7
February 01, 2013, 05:09 AM
GamP
1. get it to work in TABLE first, not Maintain. 2. when it works call tha table fex from the maintain giving it the parameter list and catching the result in a stack. Be sure the stack contains at least the exact fields table will return. Done!
GamP
- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
February 01, 2013, 05:24 AM
Shankar
Hi Frank, Yes you are right. My mistake. But can you please tell me the way to convert the comma separated string into WHERE clause string. That will really help.
Hi GamP, In my case it would require lot of code restructuring and that would be very costly affair for me as this is just a minor enhancement in an existing application. Is there any way to handle it in maintain easily as i have to deliver it urgently and i can't take more time for this.Please help.
GamP's suggestion is the right way to go and it's not terribly difficult to write.
1. Write a traditional FOCUS routine that performs your select.
TABLE FILE X PRINT A B C WHERE C IN (&1); ON TABLE PCHOLD END
That &1 is your list of values, your string 'A','AB','ABC'. It will be the variable you call the routing with. Let's call this routing select_records.fex.
2. Exchange your Maintain select for the call to the routine.
-* for all next x.a into StkRecords where x.c EQ 'a'; infer x.a into StkRecords; EXEC select_records from string_of_values into StkRecords;
3. At this point you have StkRecords filled with your values. The amper variables in your Focexec are positional -- that is the first one sent is &1, the second &2 and so on. So string_of_values arrives in &1. Your INTO stack receives the results of the select.
It's just that simple, and using FOCUS routines for your selections opens up your Maintain code to all the power of a focexec. Joins, hold files, the works. Seriously, this is the fastest, easiest way to do this. You could put together a loop in Maintain and select the values one at a time, but that's much more work than what GamP put you onto in his first post.
J.
February 04, 2013, 09:29 AM
Maintain Wizard
Here is the Maintain solution. Perform a loop and use MNTGETTOK to get the value before the comma each time through the loop. Then use the value in a NEXT with WHERE statement to add the values from the database into the stack.
MAINTAIN FILE MOVIES MODULE IMPORT(MNTUWS) COMPUTE STRING/A0 = "ROOF,WIND,TOP"; COMPUTE I/I3=1; REPEAT WHILE VAL NE '' COMPUTE VAL/A0=MNTGETTOK(STRING,",",I); REPOSITION MOVIECODE FOR ALL NEXT MOVIECODE TITLE INTO STK(STK.FOCCOUNT+1) WHERE TITLE CONTAINS TRIM(VAL) COMPUTE I=I+1; ENDREPEAT END