Skip to main content

Hi,

 

so I have an update SQL query that the sql executor transformer executes. It looks like UPDATE *TABLE_NAME* SET COLUMN_NAME = @VALUE(ATTRIBUTE_1) WHERE OTHER_COLUMN_NAME = '@VALUE(ATTRIBUTE_2)'

 

The first attribute is always a number, but the second one is a string so I have to put quotes in. But, the string can contain quotes itself, which causes the query to fail for those cases. If I put double quotes around it I get a SQL error: it thinks I'm setting it equal to the value of another column in my database table instead of a FME attribute.

 

How do I put the whole string value of attribute 2 in my where clause, quotes and all?

Thanks!

 

To update in SQL your query must be like :

UPDATE <tbl_nm>

 

SET <att_nm1> = ( your attribute name)', <att_nm2> = ( your attribute name)'

 

FROM <tbl_nm>

 

WHERE<att_nm3> = '( your attribute name)'

If it is an integer, you dont need the quotes ('). But if your update or where statement is a string, the @Value() must be between quotes.

Then, if your string contains quotes, you must double them ...

example : 'It's cold outside' become 'It'' cold outside'

It look like in your string you dont have the FROM <tbl_nm> even if you specified it in the UPDATE statement.

 

Good luck!


If it's Oracle you can specify an alternative quote character to avoid collisions with quotes in your attribute values. Here's an example where the quote character is set to #:

 ... WHERE OTHER_COLUMN_NAME = q'#@VALUE(ATTRIBUTE_2)#' 

It's documented here: https://livesql.oracle.com/apex/livesql/file/content_CIREYU9EA54EOKQ7LAMZKRF6P.html

 


To update in SQL your query must be like :

UPDATE <tbl_nm>

 

SET <att_nm1> = ( your attribute name)', <att_nm2> = ( your attribute name)'

 

FROM <tbl_nm>

 

WHERE<att_nm3> = '( your attribute name)'

If it is an integer, you dont need the quotes ('). But if your update or where statement is a string, the @Value() must be between quotes.

Then, if your string contains quotes, you must double them ...

example : 'It's cold outside' become 'It'' cold outside'

It look like in your string you dont have the FROM <tbl_nm> even if you specified it in the UPDATE statement.

 

Good luck!

Which SQL variant is this? The regular SQL syntax for updating table contents usually does not include the FROM clause:

UPDATE table_name
SET column1 = value1, column2 = value2...., columnN = valueN
WHERE condition;

 


If it's Oracle you can specify an alternative quote character to avoid collisions with quotes in your attribute values. Here's an example where the quote character is set to #:

 ... WHERE OTHER_COLUMN_NAME = q'#@VALUE(ATTRIBUTE_2)#' 

It's documented here: https://livesql.oracle.com/apex/livesql/file/content_CIREYU9EA54EOKQ7LAMZKRF6P.html

 

Thanks, this worked! 


A StringConcatenator can help with creating SQL statements as well.


Reply