SQL INSERTing multi-line text

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am importing data parsed from a txt file my ADP program. The txt file
contains a section that represents a SQL statement, complete with newlines.
Any suggestions on how to write a UPDATE or INSERT statement to push the test
string (complete with newlines) into the table?
Thanks
 
I don't quite understand which bit is giving you trouble. Is it

-parsing the SQL statement out of the text file into a string variable
which you can build into your UPDATE or INSERT query?

-building the UPDATE or INSERT query (which do you want, anyway?)?

-something else?
 
John - Sorry - I clicked the "didn't help" button accidently - sorry

I can parse the text file by using a function that pulls chucks of strings
from the file (delimited by '|'). Each segment is placed in a variable. I
wanted to then create a DoCmd.RunSQL statement "INSERT into Table" & variable.

The problem was two of the variables were multi-lined - Contained newline
characters. When those variables were concatanated to the string, it balked.

But I think it's due to the single-quotes that were in the string.

I think I've solved the problem by REPLACING the single quote with a '~'
before running the DoCmd.RunSQL statement. Then UPDATING the fields and
REPLACING the `~' with a single quote.

Is there a better way to INSERT text that contains single quotes?
 
IIRC you just need to replace each single quote ' in the data with a
pair of them '' (not a double quote), e.g.

INSERT INTO ... VALUES ('Text value', 'String ''containing'' quotes',
....

The duplicates are stripped out in the import process.
 
Back
Top