|
-
Jun 3rd, 2007, 10:14 AM
#1
Thread Starter
Addicted Member
Problem added text to the end of existing text field...
Hi,
I need some help, as always, I currently have a table called 'notificationMessageTbl' and I have a TEXT field called 'userReadID' what I want to do is add text to the end of current text within the field using SQL
If I use the following code it just replaces the exsisting text with '12,' and does not append.
Code:
UPDATE notificationMessageTbl SET userReadID = '12,'
Thanks in advance
Simon
-
Jun 3rd, 2007, 10:18 AM
#2
Re: Problem added text to the end of existing text field...
You can use the field name to retrieve the existing value, and append it to your value, eg:
Code:
UPDATE notificationMessageTbl SET userReadID = userReadID + '12,'
I would recommend using a Where clause, as this currently alters all rows of your table (and is likely to have errors if the field is currently Null in any rows).
-
Jun 3rd, 2007, 10:21 AM
#3
Thread Starter
Addicted Member
Re: Problem added text to the end of existing text field...
Unfortunately this give the following error which I think is because the field is a TEXT field not a varchar field....
Invalid operator for data type. Operator equals add, type equals text.
Thanks for the recommendation about the WHERE clause.
Thanks
Simon
-
Jun 3rd, 2007, 10:25 AM
#4
Re: Problem added text to the end of existing text field...
Which database system are you using?
Assuming SQL Server (I think that's the message it shows!), you could try this:
Code:
userReadID = Cast(userReadID as VarChar(Length(userReadID)))+ '12,'
..note that this will only work if the length of the field is within the limits of the VarChar data type.
-
Jun 3rd, 2007, 10:29 AM
#5
Thread Starter
Addicted Member
Re: Problem added text to the end of existing text field...
Sorry to ask a stupid question, but will the code look like this:
Code:
UPDATE notificationMessageTbl SET userReadID = Cast(userReadID as VarChar(Length(userReadID)))+ '12,'
Also I am using SQLServer
Thanks
Simon
-
Jun 3rd, 2007, 10:30 AM
#6
Re: Problem added text to the end of existing text field...
That's correct.
-
Jun 3rd, 2007, 10:36 AM
#7
Thread Starter
Addicted Member
Re: Problem added text to the end of existing text field...
Thanks, just wanted to check as I tried that and it gave the following error:
Line 1: Incorrect syntax near 'Length'.
Thanks for all your help
Simon
-
Jun 3rd, 2007, 10:39 AM
#8
Re: Problem added text to the end of existing text field...
Oops.. I sometimes get confused and use the syntax from one DBMS in another. 
I just checked Books Online, and it looks like it should be Len instead of Length.
-
Jun 3rd, 2007, 10:46 AM
#9
Thread Starter
Addicted Member
Re: Problem added text to the end of existing text field...
Sorry to be a pain , but it's still give me an error:
Line 1: Incorrect syntax near 'Len'.
Thanks
Simon
-
Jun 5th, 2007, 01:22 AM
#10
Re: Problem added text to the end of existing text field...
Try this
Code:
UPDATE notificationMessageTbl SET userReadID = Cast(userReadID as VarChar(16))+ '12,'
16 is len of TEXT datatype
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|