I've got an SQL Insert statement that inserts about 100 fields (1 record) into a table. Most of these fields are text, so it's possible they may contain single quotes. These quotes need to be escaped in the insert statement so I was hoping to just use the replace function...eg:
INSERT INTO Tab1 (Field1, Field2...etc) VALUES ('" & replace(field1, "'", "''") & "', '" & replace(field2, "'", "''") & "')"
The problem with this is that some of these fields may be NULL and the replace function blows up on a NULL value (Invalid use of Null: 'replace'). Do I have to do a condition on every field before my statement like:
if not ISNULL(field1) then
field1 = replace(field1, "'", "''")
end if
It just seems a hassle to do this 100 times for each field.
Thanks.
INSERT INTO Tab1 (Field1, Field2...etc) VALUES ('" & replace(field1, "'", "''") & "', '" & replace(field2, "'", "''") & "')"
The problem with this is that some of these fields may be NULL and the replace function blows up on a NULL value (Invalid use of Null: 'replace'). Do I have to do a condition on every field before my statement like:
if not ISNULL(field1) then
field1 = replace(field1, "'", "''")
end if
It just seems a hassle to do this 100 times for each field.
Thanks.