Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Using Varchar(max) to add to a field?


Using Varchar(max) to add to a field?

Author
Message
mick burden
mick burden
Old Hand
Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)

Group: General Forum Members
Points: 305 Visits: 431
Merry Holidays everyone, I've created a basic table which includes a text field. I then created a SP which basically read the text field and then added to the same field, the problem is I get an error that says I can't use TEXT or Varchar(Max), is there a way round this?

Table


CREATE TABLE KLN
(RecId INT IDENTITY(1,1) PRIMARY KEY CLUSTERED,
Dte DATETIME,
machineid VARCHAR(50),
Userid VARCHAR(50),
memo text)





Stored Procedure

CREATE PROCEDURE [dbo].[Save_kln]
@sDte as datetime,
@smachineid as varchar(50),
@sUserid as varchar(50),
@smemo as text

AS
DECLARE @sRESULTS varchar(MAX)
if exists (select * from [kln] where [dte] = @sdte and Userid = @Suserid)
begin
set @sRESULTS = (select memo from [kln] where [dte] = @sdte and Userid = @Suserid)
update [kln] set memo = @sRESULTS + @smemo where [dte] = @sdte and Userid = @Suserid
end
else
begin
INSERT INTO [kln] (dte,machineid,userid,memo) VALUES (@sdte,@smachineid,@suserid,@smemo)
end


GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47345 Visits: 44392
You shouldn't be using TEXT in the first place, it's an old SQL 2000 data type, included only for backward compatibility. Use Varchar(max)


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


mick burden
mick burden
Old Hand
Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)

Group: General Forum Members
Points: 305 Visits: 431
GilaMonster (12/27/2012)
You shouldn't be using TEXT in the first place, it's an old SQL 2000 data type, included only for backward compatibility. Use Varchar(max)



Varchar(Max) isn't allowed in my situation either
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47345 Visits: 44392
Post your code with the varchar(max) used and post the exact error message


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


mick burden
mick burden
Old Hand
Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)

Group: General Forum Members
Points: 305 Visits: 431
turns out what you suggested did work after all, I'd like to thank you for your help
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search