Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 18th, 2009, 07:30 PM
Authorized User
 
Join Date: Sep 2004
Posts: 68
Thanks: 1
Thanked 0 Times in 0 Posts
Default Problem w/ concatenation during update

Hello.

SQL Server update issue:

I want to be able to append data to a comments field when I update my table however, the code below gives me this error: Server: Msg 403, Level 16, State 1, Line 6
Invalid operator for data type. Operator equals add, type equals text. note that comments is a text field on roomreservationseriesmaster.

declare @comments varchar(50)
set @comments = 'stuffff'

update roomreservationseriesmaster
set comments = @comments + comments
 
Old May 18th, 2009, 08:32 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Yep, read the SQL Server docs:

http://msdn.microsoft.com/en-us/libr...2(SQL.80).aspx

Quote:
Syntax

expression + expression
Arguments

expression
Is any valid Microsoft® SQL Server™ expression of any of the data types in the character and binary data type category, except the image, ntext, or text data types.

You are hosed.

Now, that's for SQL Server 2000.

But the docs for SQL Server 2008 say the same thing:
http://msdn.microsoft.com/en-us/library/ms177561.aspx

So... I don't see how you can do this via an UPDATE statement.

You may have to read the data into an app (e.g., C# or VB.NET code), perform the concatenation, and then update the entire TEXT field at one go.
 
Old May 19th, 2009, 03:16 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

That's one of the reasons not to use the text data type in more modern versions, use nvarchar(max) instead if available.
However you can update but you need to get a pointer to the field and then use specialised methods. See http://msdn.microsoft.com/en-us/library/ms189466.aspx
__________________
Joe
http://joe.fawcett.name/
 
Old May 19th, 2009, 05:26 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Quote:
Originally Posted by srotondo View Post
Hello.

SQL Server update issue:

I want to be able to append data to a comments field when I update my table however, the code below gives me this error: Server: Msg 403, Level 16, State 1, Line 6
Invalid operator for data type. Operator equals add, type equals text. note that comments is a text field on roomreservationseriesmaster.

declare @comments varchar(50)
set @comments = 'stuffff'

update roomreservationseriesmaster
set comments = @comments + comments
There is a RBAR (Row By Agonizing Row) way to do this on a TEXT datatype but it can only be one row at a time... still interested?
__________________
--Jeff Moden
 
Old May 20th, 2009, 08:19 AM
Authorized User
 
Join Date: Sep 2004
Posts: 68
Thanks: 1
Thanked 0 Times in 0 Posts
Default thank you

Good morning all and thank you for your responses.

Seems like this update is very difficult therefore, I plan to use a simple work-around: read my table, extract the comments field, append the new comments to the field in ASP and then update the table.

sal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Concatenation question, please savoym VBScript 12 May 5th, 2009 02:30 PM
Aggregate Concatenation 12th_Man SQL Language 4 January 10th, 2006 03:26 PM
Concatenation of fields JpJoe Access 8 April 8th, 2005 01:32 AM
string concatenation nulogix PHP How-To 1 June 24th, 2004 06:17 AM
string concatenation matt_99 Access VBA 2 January 17th, 2004 09:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.