Escape Character in SQL

Please forgive me as I am a little sql noob. I am trying to do an insert using the following, but I have a problem with apostrophes. I have many records to insert, but many have the same problem. Is there any way to avoid them?

INSERT INTO  [dbo].[tb_Chefs] ([ChefHotelID], [HotelID], [ChefID],   
     [Position],  [GroupID])  
VALUES(N'b809a86e-f7f2-45b2-a240-0049f51509d7' ,N'14481', N'624', 
     N'Chef d'atelier', N'331')
GO

Any help is greatly appreciated.

+3
source share
3 answers

'Chef d'atelier' becomes 'Chef d''atelier'

Just double them

If a string of characters enclosed in single quotation marks contains an embedded quotation mark, they are an embedded single quotation mark with two single quotation marks.

+7
source

You can also use the ESCAPE clause. This allows you to define your own escape character.

+1
source

-

INSERT INTO [dbo].[tb_Chefs] ([ChefHotelID], [HotelID], [ChefID], [Position], [GroupID])
VALUES("N'b809a86e-f7f2-45b2-a240-0049f51509d7'" ,"N'14481'", "N'624'", "N'Chef d'atelier', N'331'")

, , SQL .

0
source

Source: https://habr.com/ru/post/1756428/


All Articles