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.
| 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.HHCREATE procedure "update_data" @c1 int,@c2 nvarchar(50),@c3 nvarchar(2000), @c4 nvarchar(50)ASif @c4 = 'update'beginupdate "data2" set"ID" = @c1,"Name" = @c2 where "ID" = @c1endelseBEGINinsert into "data2"( "ID", "Name", "Add" )values ( @c1, @c2, @c3 )ENDGO" |
|
|
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.HHCREATE procedure "update_data" @c1 int,@c2 nvarchar(50),@c3 nvarchar(2000), @c4 nvarchar(50)ASif @c4 = 'update'beginupdate "data2" set"ID" = @c1,"Name" = @c2 where "ID" = @c1endelseBEGINinsert into "data2"( "ID", "Name", "Add" )values ( @c1, @c2, @c3 )ENDGO"
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 GOcall the procedure as :1,'update','test','test1'regards,harshal.Expect the UnExpected |
 |
|
|
|
|
|
|
|