Focal Point
[CLOSED] SQL WHERE clause via SQL passthrough

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/8341067331

September 24, 2003, 03:21 PM
Rich Dickeson
[CLOSED] SQL WHERE clause via SQL passthrough
In FOCUS you can build the following statement

WHERE field IN FILE TEMP

where TEMP has a list of values to use against the field. This works great

IN SQL the WHERE statement can use a list also

WHERE field IN (val1,val2,val3)

Here is my question..
Is there a technique within FOCUS to pass a file that contains a list of values to SQL Pass through. It would look like this

WHERE field IN (TEMP)

and TEMP would contain val1, val2, val3

Thanks in advance

This message has been edited. Last edited by: Kerry,
September 24, 2003, 06:09 PM
<Pietro De Santis>
Rich,

I don't think waht you require is possible. If you look at the SQL generated by a FOCUS TABLE request that includes a WHERE IN FILE statement, you will se that it is translated as WHERE XXX IN ('qqq', 'www', 'eee'). As well, there does not appear to be any SQL syntax where you can have your selection values in a file. So I don't think FOCUS can generate the SQL WHERE clause like you want.

Regards,

Pietro.
September 26, 2003, 08:36 AM
<Grzegorz>
Rich,

You can use some DM commands to generate the appropriate SQL PASSTHROUGH query based on the values read from a file. This is a simple example:

1. The text file filter.txt (resides in the '$IBI_HOME/apps/tests' directory):
ENGLAND,$
FRANCE,$
JAPAN,$
2. The master file filter.mas:
FILE=FILTER,SUFFIX=COM
SEGNAME=FILTER, SEGTYPE=S01
FIELDNAME=COUNTRY, COUNTRY,A10,A10,$
3. The focexec procedure:
-*APP PATH tests
APP FI FILTER tests/filter.txt
-*
TABLE FILE FILTER
PRINT COUNTRY
ON TABLE HOLD FORMAT ALPHA
END
-RUN
-IF &RECORDS LE 0 THEN GOTO :FINISH;
-READ HOLD &NAME.A10.
SQL
SELECT COUNTRY FROM CAR
WHERE COUNTRY IN
(
'&NAME'
-REPEAT :LOOP FOR &CNT FROM 2 TO &RECORDS
-READ HOLD &NAME.A10.
,'&NAME'
-:LOOP
);
END
-:FINISH

Hope this helps
Grzegorz
October 17, 2003, 11:10 AM
Tewy
What you want to do is possible in Focus. You need to filedef to the file you have your values stored in (I've only ever used TXT files or FTM file created by Focus).

The syntax for your report is

IF fieldname IS (filename)

Note the IF statement has to go at the bottom of any WHERE statements you may be using. Don't put a semi-colon on the end of your IF statement. Your file can only have up to 1000 values in it.

In a similar vain you can do

IF fieldname IS-NOT (filename) etc

Regards

Tewy
February 27, 2012, 09:54 AM
n00b
Have there been any changes/enhancements to this methodology in the last 9 years? I need to do the same thing (pass values from a FOCUS file to a SQL where clause.


WebFOCUS 7.7.03
AIX 5.2
HTML, AHTML, PDF, EXCEL, XML
February 27, 2012, 12:46 PM
dojo
Another method that has worked efficiently for me in a few applications is to create a SQL table with two columns; one, the userid of the user making the request AND two, the values from the file. Load the values, then you can do an inner join to the values and include the userID as part of the WHERE clause. Depending on your specific DBMS you can make the userID column a NUPI and do a DELETE FROM when you are finished and there would be no contention to clear out the temporary list of values for the next run. Hope that makes sense.


Linux/zVM/WF7.6.11