Update field with original value plus new value

Krapulator
Krapulator used Ask the Experts™
on
I have a stored procedure which should add a value to an existing field, not replace it. I can't seem to work out the correct syntax to do so.

heres the proc:

@id int,
@sHistory varchar(5000)
AS
Update dbo.Application
SET sHistory = sHistory + @sHistory
WHERE ApplicationId = @id

This procedure doesnt work, ive tried a few different things, but being a newbie to stored procs, I just cant seem to work it out.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Well, syntax for the update looks fine and should work. If it didn't, it should error (e.g. adding different data types).

Have you tried dropping the variables and hard coding values in the update statement to see if your results change?

Author

Commented:
maybe I should have mentioned that the sHistory table is actually a text data type.

I am getting an error in the stored procedure editor on sql server.

It must be because im passing it as a varchar instead of a text.
Commented:
I see - you are just getting a syntax error.

Try running the statements in Query Analyzer to find out where the problem is.

You may need to explicity convert - something like:

Update dbo.Application
SET sHistory = sHistory + cast(@sHistory as text)
WHERE ApplicationId = @id

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial