The problem with editing large texts in SQL Backend is that the text is broken up into separate lines, so the “carriage return” character at the end of the first line is interpreted by anything SQL as the “I’ve finished typing, now go do that” command.
The quickest way around it is simply to update the table using standard SQL commands (i.e. update tablename set field=value where….). Now usually, you would simply put the value bit in single quotes and run the SQL, but you have the added complication that the text contains single quotes itself, and the way to specify single quotes as literals is putting a single quote before it (i.e. ” – which is obviously not the same as the ” double quote even if it looks the same on screen).
Therefore, I would suggest doing the following (name of the textfield is ‘comment’ and ‘logid’ is the unique identifier):
- Open up a new query window in SQL Server Management Studio, pointing to the database.
- Paste in the following code:set quoted_identifier ONdeclare @comment varchar(8000), @logid int
set @logid =
set @comment = ”
set comment = @comment
where logid = @logid
- Paste the text you want to change into Notepad, change it and then do an Edit Replace, replacing single quote ‘ with double quote ” and replace all instances.
- Do a Select All, and copy the text.
- Paste what you have on the clipboard into the SSMS query window between the two single quotes next to @Comment, so the text you copied gets assigned to the @comment variable.
- Specify the logid number to identify the record to be updated.
- Run the code.
It looks like a lot of steps, but once you’ve gone through it once, you’ll see it’s not much work at all, and certainly much quicker than scrolling through the field.
An alternative way could be to use the REPLACE function as follows:
set comment = replace(convert(varchar(8000), comment), ‘put what you want replaced here within the single quotes’, ‘put the new text you want here within the single quotes’)
where logid = ‘replace this string including single quotes with the logid number of the record you want changed’
set comment = replace(convert(varchar(8000), comment), ‘Test result from yesterday, ‘Test result from today’)
where logid = 132
That way, you don’t need to copy large amounts of text out and in again, since you’re just changing small bits of it.