Saturday, August 21, 2010

You can't escape single quotes in SQL inserts with \

To escape single quote marks in DB2 SQL inserts you cannot use the backslash character. This will NOT work:

insert into LCDDB_NCD_BNFT_CTGRY_REF (BNFT_CTGRY_CD,BNFT_CTGRY_DESC,BNFT_CTGRY_EFCTV_DT,BNFT_CTGRY_TRMNTN_DT)
values (52,'Physicians\' Services','2002-8-2',null)

To insert a single quote mark in DB2 with SQL insert you have to replace single quotes with two (2) single quotes.

insert into LCDDB_NCD_BNFT_CTGRY_REF (BNFT_CTGRY_CD,BNFT_CTGRY_DESC,BNFT_CTGRY_EFCTV_DT,BNFT_CTGRY_TRMNTN_DT)
values (52,'Physicians'' Services','2002-8-2',null)


No comments:

About Me

My photo
Lead Java Developer Husband and Father

Tags