1

How I can do a insert of sql syntax inside of varchar in mysql?

example:

INSERT INTO vartemp (SQLSyntax)
VALUES ('UPDATE RegExample SET Field1 = 'abc', Field2 = 123 WHERE whereCond1 = 'abc'')

where:

Vartemp is my table of SQL Syntax.

RegExample is a example of table.

ElGavilan
  • 6,610
  • 16
  • 27
  • 36
Lucas Selliach
  • 189
  • 1
  • 3
  • 10

2 Answers2

2

Is this what you want?

INSERT INTO vartemp (SQLSyntax)
    VALUES ('UPDATE RegExample SET Field1 = ''abc'', Field2 = 123 WHERE whereCond1 = ''abc''')

If so, all you need to do is properly escape the embedded single quotes in the string. The escape method for a single quote is two single quotes.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
1

simple:

change ' to double ''

Pierry
  • 979
  • 7
  • 17