How do I append data on an update?
I have a table with a field that is nVarchar(1000) and the initial insert is a few sentences. If I wanted to add to that row using an update statement and without starting at the end of the sentences, how would I write that?
Update table set fieldname = 'more data' where value = @.variable
instead of
Update table set fieldname = 'initial data more data' where value = @.variable
and the 'more data' appends to the initial data... hmmm
help please.I'm not exactly following you. If you want to do both an INSERT and an UPDATE you need 2 different commands.
INSERT INTO table (ID, fieldname) VALUES(@.MyID, 'initial data')
UPDATE table SET fieldname = fieldname + ' more data' WHERE ID = @.MyID
Maybe you could explain further?
Terri|||OK, lets see...
An existing field containing data:
'A small red dog crapped on my lawn.'
In a textbox append to that same field:
'Then the owner cleaned it up.'
So now the field will contain:
'A small red dog crapped on my lawn. Then the owner cleaned it up.'
If i perform the statement like this:
Inset Into table (fieldname) Values ('Then the owner cleaned it up.') where value = @.value
Won't the 'A small red dog crapped on my lawn.' part be overwritten?|||No, you'd get an error ;-) You can't put a WHERE on an INSERT. What you need is an UPDATE:
UPDATE table SET fieldname = RTRIM(fieldname) + 'Then the owner cleaned it up.' WHERE value = @.value
(Note that you'd only need the RTRIM if the datatype of that field is char. Varchar data will not have extra spaces padding it out to the field length.
Terri
No comments:
Post a Comment