February 19, 2009 at 5:55 pm
Hi,
I want to add data to existing data, meaning
I don't want to update it just add to it.
here is my table
CREATE TABLE [dbo].[Articles](
[ArticleID] [int] IDENTITY(1,1) NOT NULL,
[categoryID] [tinyint] NOT NULL,
[Creation] [smalldatetime] NOT NULL,
[Title] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Body] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Author] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_Articles] PRIMARY KEY CLUSTERED
I want to add data to the Body column at a certain
ArticleIDI just want to add more text to the article.
Can you finish the sproc below so I can do that.
I can't figure it out.
Here is the sproc I was playing with:
ALTER PROCEDURE [dbo].[AddTextToArticle]
-- Add the parameters for the stored procedure here
@ArticleID int,
@Body text
AS
INSERT INTO Articles(Body) VALUES(@Body)
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT
ArticleID = @ArticleID
Thanks
Steve
Ask An Expert Online, Mechanics Doctors Plumbers etc. Save Your Money Ask Our Experts!
Ask A Mechanic
February 20, 2009 at 4:38 am
You still need to use the update statement.
I would avoid the use of the 'text' datatype. Something like this below but remember you need to work on the error trapping for this stored procedure.
CREATE TABLE [dbo].[Articles](
[ArticleID] [int] IDENTITY(1,1) NOT NULL,
[categoryID] [tinyint] NOT NULL,
[Creation] [smalldatetime] NOT NULL,
[Title] [varchar](100) NULL,
[Body] [varchar](max) NULL,
[Author] [varchar](30) NULL )
GO
Create PROCEDURE [dbo].[AddTextToArticle]
@ArticleID int,
@Body varchar(max)
AS
BEGIN
UPDATE articles
set body = isnull(body,'') + @body
where articleid = @articleid
END
GO
insert articles (categoryid,creation)
select 1,getdate()
GO
addtexttoarticle 1,'In the beginning '
select * from articles
GO
addtexttoarticle 1,'In the middle '
select * from articles
GO
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply