error using XML in sql query - sql

query is some thing like
update table set configXML='XML' where...
here in XML i have a tag, which contains
Url="javascript:OpenEntityEditor(**'../Entity/EntityEditor.aspx?CNodeID={0}'+','+'resizable=yes,maximize=1'+','+'{0}'**);"
in above line, bond area is throwing error. How pass it as it is? Please guide me.

single quote (') is not allowed in sql query more than once so if there is requirement to use (') more than once then just replace (') with 2 single quotes (''). for example :-
Url="javascript:OpenEntityEditor(''../Entity/EntityEditor.aspx?CNodeID={0}'',''resizable=yes,maximize=1'',''{0}'');"

Related

How to insert a char value enclosed in square brackets. Getting error column 'value' does not exist in the 'table'?

Hi,
I am trying to insert a value "['HCC111', 'HCC112']" in a redshift column but getting an error which says column "['HCC111', 'HCC112']" does not exist in the table. Is there a workaround for this ?
Query:
insert into #trhcc values('COMMUNITY V22', "['HCC111', 'HCC112']",'HCC10')
Here is the snapshot of the query that is submitted --
"['HCC111', 'HCC112']" is not a valid way because you used doube quotes. Text must use single quotes. Your problem is that you also use single quotes in your entry text. That is easily solved by escaping your single quotes. You do that by doubling the single quote like so:
'[''HCC111'', ''HCC112'']'

Nested sql statement in talend (updated)

I am trying to use nested sql in postgresql tPostgresqlRow_1.
But I receive an error.
The following sql runs okay if I run it in PgAdmin.
But in Talend I receive an error.
I am getting the max date from one table and updating the column in another table.
update "STG_magento_de"."configuration_table"
set created_at=(select MAX(created_at) from "STG_magento_de"."sales_flat_order_test")
where table_name='sales_flat_order_test'
The tPostgresqlRow component expects a Java string containing the SQL statement.
The most likely problem is that you have unescaped quotes in the statement. That works fine in pgAdmin because it is valid. To pass the same statement from Talend, you'll have to escape all the quotes in the statement itself. Alternatively, you could try removing the double quotes from the SQL statement.
Remember to enclose the whole thing in quotes, so that it is a proper Java string.
create or replace function eliminarComillas (text) returns text AS $$
select replace(replace(replace($1,'**\"**','"'),'‘','‘'),'’','’');
$$ language sql;"
Following sql with escape quotes worked.
"update \"STG_magento_de\".\"configuration_table\"
set created_at=(select MAX(created_at) from \"STG_magento_de\".\"sales_flat_order_test\")
where table_name='sales_flat_order_test'"

how to write a word to a database that is between 2 Apostrophes?

I have a table in my database of type nvarchar(50);
I want to write to that specific column that string 'Tal' - Tal between 2 apostrophes.
When I'm trying to do so what is recorded in my DB is "Tal" - Tal between 2 quotation marks.
My database is an SQL database and so are my scripts.
How this can be solved?
The standard way to do what you want is this.
insert into mytable ( mycolumn ) values ('''Tal''');
The first and last ' are the start and end markers for the string. Each '' within these characters means '. Refer to page 89 of the SQL 92 specification at http://www.andrew.cmu.edu/user/shadow/sql/sql1992.txt
I think escaping is the key to your question. For SQL apostrophes are special characters, thus they have to be escaped by '' (two apostrophes). Have you checked that your scripts do not add the second apostrophe for you? Probably you have to add Tal without the apostrophes.
Escape % seems to be DB dependant. Oracles uses \%, others accespt [%] and some seem to have a keyword ESCAPE. You have read the documentation of your database, look for "escape characters".
Try inserting like this using the backslash \'Tal\'.

Special character in varchar in SQL

I am inserting text from a file into a table, few of the lines have words like "you'll" or "don't". When I insert these lines as varchar in my table, I get an error saying - near "ll": syntax error. How do I overcome this?
Your single quote is being considered as the end of your string. Escape the quote that exists within your string to avoid this problem.
You need to escape your SQL statement. If you are using SQL Server, then you can use QUOTENAME to resolve this.
Use two apostrophes within apostrophe-quoted strings to insert the apostrophe:
insert into footable (foo) values('you''ll')
Thank you all for responses, since I was using sqlite3, there are inbuilt string formating functions available with the library, so I was able to use sqlite3_mprintf with %q instead of %s and it took care of single quotes.

How does one escape an apostrophe in db2 sql

I'm looking for the db2 equivalent of T-SQL's:
INSERT INTO People (Surname) VALUES ('O''Hara');
Use two apostrophes '' to get a single apostrophe on DB2 too, according to the DB2 Survival Guide. Isn't that working for you?
Brabster is correct. You are supposed to escape ' with ''
So to insert O'Hara , you will have to write O''Hara
Excerpt from:
http://www.michael-thomas.com/tech/db2/db2_survival_guide.htm
Escape character.
To insert a single quote, use 2 single
quotes ( '' ). To insert pet's use
the following pet''s.
Example: insert into MYTABLE (question,answer) values ('What is
your pet''s name?','blacky') `
just make it simple.
Keep your query in the single quotes ('). and where ever you are using qoutes, make it double.
for e.g. u want to insert ...... I'm fine. There's an answer.
in SQL we need to give ....... 'I''m fine. There''s an answer.'
I was trying to insert into DB2 a regex expression for an email address. I thought I had to escape all characters as outlined at the proceeding link, but escaping only the single quote contained within the regex seems to be all I needed to escape to get it properly inserted into the database:
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.1.0/com.ibm.db2.luw.admin.ts.doc/doc/c0059609.html