-1

Here is my insert query

INSERT INTO
    Customers (CustomerId, ContactNumber, MsgContent, City, PostalCode, Country)
VALUES 
    (1, '123456', '["https://picsum.photos/id/237/200/300","Gift your Dear one' s with surprise gifts"," abc "," 123 "," xyz "]', ' mno ', 012, ' pqr ') ;

SQL is showing syntax error while executing this query.

How to solve this issue?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sulu
  • 1
  • 1
  • Search stackoverflow first for similar questions. https://stackoverflow.com/questions/1586560/how-do-i-escape-a-single-quote-in-sql-server – Nils Jul 05 '22 at 11:19
  • Can you post the error you are getting? I think the ' by the text one's is causing an issue. It closes the opening ' before [ in MsgContent. – Predator Jul 05 '22 at 11:27
  • Normally, you can fix this issue by having double quote, so it would not be "Gift your Dear one' s" but "Gift your Dear one'' s" – LPK Jul 05 '22 at 11:31
  • this is why you should use bind parameters if possible – OldProgrammer Jul 05 '22 at 11:31
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 05 '22 at 22:02

1 Answers1

-1

I would recommend using backticks here as it'll allow you use " and ' at the same time. For example, try the following for your VALUES:

INSERT
    INTO
    Customers (CustomerId,ContactNumber, MsgContent, City, PostalCode, Country)
VALUES 
(1,'123456',`["https://picsum.photos/id/237/200/300","Gift your Dear one' s with surprise gifts," abc "," 123 "," xyz "]`, ' mno ', 012, ' pqr ') ;

Note the backticks that open and close your MsgContent field.

Predator
  • 138
  • 1
  • 7