Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Stored Proc Problem

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-03-03 : 07:30:23
Hock Heng writes "Hi all,

I am new to stored proc.I have created a snippets of code below, but sql server keep giving like "must declare @c4..." can anybody help???

Thanks.

HH


CREATE procedure "update_data" @c1 int,@c2 nvarchar(50),@c3 nvarchar(2000), @c4 nvarchar(50)
AS
if @c4 = 'update'
begin
update "data2" set
"ID" = @c1
,"Name" = @c2
where "ID" = @c1
end
else
BEGIN
insert into "data2"(
"ID", "Name", "Add"
)
values (
@c1, @c2, @c3
)
END


GO"

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-03-03 : 08:18:34
quote:

Hock Heng writes "Hi all,

I am new to stored proc.I have created a snippets of code below, but sql server keep giving like "must declare @c4..." can anybody help???

Thanks.

HH


CREATE procedure "update_data" @c1 int,@c2 nvarchar(50),@c3 nvarchar(2000), @c4 nvarchar(50)
AS
if @c4 = 'update'
begin
update "data2" set
"ID" = @c1
,"Name" = @c2
where "ID" = @c1
end
else
BEGIN
insert into "data2"(
"ID", "Name", "Add"
)
values (
@c1, @c2, @c3
)
END


GO"


the following code worked fine for me:
create procedure update_data
@c1 int,@c2 nvarchar(50),
@c3 nvarchar(2000),
@c4 nvarchar(50)
AS
if @c4 = 'update'
begin
update data2 set ID = @c1 ,Name = @c2 where ID = @c1
end
else
BEGIN
insert into data2( ID, Name,"Add" ) values ( @c1, @c2, @c3 )
END


GO



call the procedure as :
1,'update','test','test1'


regards,
harshal.

Expect the UnExpected
Go to Top of Page
   

- Advertisement -