I have a field that has has a value with an apostrophe.
So, I do a simple TABLE FILE as follows:
TABLE FILE MYTABLE PRINT * WHERE MYFIELD EQ 'O''Brien'; END
Doesn't work.
TABLE FILE MYTABLE PRINT * WHERE MYFIELD EQ 'O'Brien'; END
Doesn't work.
TABLE FILE MYTABLE PRINT * WHERE MYFIELD EQ 'O' || '''' || 'Brien'; END
Works.
REALLY? I have to convert the &var that represents the value O'Brien to all that? I'm getting a headache just thinking about the steps I have to go through to do it, especially since the value is coming from a multi-select combobox with values in quotes separated by OR... I already have a headache thinking about converting ' to '' as it is.
Okay, so... first of all, is there some trick to multi-select that will double apostrophe the apostrophes as it adds the quotes and OR?
Secondly, do I really have to split the apostrophes out and concatenate them to the rest of the values?
Have I gone cuckoo?This message has been edited. Last edited by: <Emily McAllister>,
WF 8.1.05 Windows
January 06, 2016, 12:47 AM
j.gross
Once you manage to stuff O'Brien into &var, e.g.
-DEFAULT &var=O'Brien
use
WHERE MYFIELD EQ &var.QUOTEDSTRING;
January 07, 2016, 10:06 AM
BabakNYC
I just tested this in WF 8105 and 'O''Brien' works. The data is in a FOCUS file.
WebFOCUS 8206, Unix, Windows
January 07, 2016, 11:37 AM
Francis Mariani
Also, turn SQL traces on to see the SQL generated by WF. Your original code should work.
Francis
Give me code, or give me retirement. In FOCUS since 1991
Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
January 08, 2016, 06:13 AM
Ricardo Augusto
Creating a Standard Quote-Delimited String
Character strings must be enclosed in single quotation marks to be handled by most database engines. In addition, embedded single quotation marks are indicated by two contiguous single quotation marks. Quotation marks are required around variables containing delimiters, which include spaces and commas. The QUOTEDSTRING suffix on a Dialogue Manager variable applies the following two conversions to the contents of the variable: Any single quotation mark embedded within a string is converted to two single quotation marks.
Single quotation marks are added around the string. Dialogue Manager commands differ in their ability to handle character strings that are not enclosed in single quotation marks and contain embedded blanks. An explicit or implied - PROMPT command can read such a string. The entire input string is then enclosed in single quotation marks when operated on by .QUOTEDSTRING.
Note: When using the -SET command to reference a character string, ensure the character string is enclosed in single quotes to prevent errors.
Syntax: How to Create a Standard Quote-Delimited Character String &var.QUOTEDSTRING where: &var Is a Dialogue Manager variable.
Creating a Standard Quote-Delimited Character String The following example shows the results of the QUOTEDSTRING suffix on input strings. -SET &A = ABC; -SET &B = 'ABC'; -SET &C = O'BRIEN; -SET &D = 'O'BRIEN'; -SET &E = 'O''BRIEN'; -SET &F = O''BRIEN; -SET &G = OBRIEN'; -TYPE ORIGINAL = &A QUOTED = &A.QUOTEDSTRING -TYPE ORIGINAL = &B QUOTED = &B.QUOTEDSTRING -TYPE ORIGINAL = &C QUOTED = &C.QUOTEDSTRING -TYPE ORIGINAL = &D QUOTED = &D.QUOTEDSTRING -TYPE ORIGINAL = &E QUOTED = &E.QUOTEDSTRING -TYPE ORIGINAL = &F QUOTED = &F.QUOTEDSTRING -TYPE ORIGINAL = &G QUOTED = &G.QUOTEDSTRING
The output is: ORIGINAL = ABC QUOTED = 'ABC' ORIGINAL = ABC QUOTED = 'ABC' ORIGINAL = O'BRIEN QUOTED = 'O''BRIEN' ORIGINAL = O'BRIEN QUOTED = 'O''BRIEN' ORIGINAL = O'BRIEN QUOTED = 'O''BRIEN' ORIGINAL = O''BRIEN QUOTED = 'O''''BRIEN' ORIGINAL = OBRIEN' QUOTED = 'OBRIEN'''
Note: The -SET command will remove single quotes around a string. Notice in the example above that the result of -SET &B = 'ABC' was changed to ORIGINAL = ABC (as shown in the output), prior to the QUOTEDSTRING conversion.