A
Andy
Hi all,
I'm trying to write code which will create a stored procedure in the
database. The code uses a command object to execute the following sql:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE apPersonDelete
@PersonId int,
@AuditUserId int
AS
declare @result bit
set @result = -1
delete
from [Person]
where PersonId = @PersonId
if @@error = 0 begin
set @result = 0
end
return @result
go
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE apPersonUpdate
@PersonId int,
@FirstName varchar(50),
@LastName varchar(50),
@BirthDate datetime,
@Sex char(1),
@Weight decimal,
@SecurityId uniqueidentifier,
@AuditUserId int
AS
declare @result bit
set @result = -1
update [Person]
set FirstName = @FirstName,
LastName = @LastName,
BirthDate = @BirthDate,
Sex = @Sex,
Weight = @Weight,
SecurityId = @SecurityId
where PersonId = @PersonId
if @@error = 0 begin
set @result = 0
end
return @result
go
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE apPersonInsert
@FirstName varchar(50),
@LastName varchar(50),
@BirthDate datetime,
@Sex char(1),
@Weight decimal,
@SecurityId uniqueidentifier,
@PersonId int output,
@AuditUserId int
AS
declare @result bit
set @result = -1
insert into [Person]( FirstName, LastName, BirthDate, Sex, Weight,
SecurityId )
values ( @FirstName, @LastName, @BirthDate, @Sex, @Weight, @SecurityId
)
if @@error = 0 begin
set @PersonId = scope_identity()
set @result = 0
end
return @result
go
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
It runs fine in query analyzer, but when i try it via the command
object, i get errors about @result already being declared and syntax
error near create procedure.
Any ideas?
I'm trying to write code which will create a stored procedure in the
database. The code uses a command object to execute the following sql:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE apPersonDelete
@PersonId int,
@AuditUserId int
AS
declare @result bit
set @result = -1
delete
from [Person]
where PersonId = @PersonId
if @@error = 0 begin
set @result = 0
end
return @result
go
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE apPersonUpdate
@PersonId int,
@FirstName varchar(50),
@LastName varchar(50),
@BirthDate datetime,
@Sex char(1),
@Weight decimal,
@SecurityId uniqueidentifier,
@AuditUserId int
AS
declare @result bit
set @result = -1
update [Person]
set FirstName = @FirstName,
LastName = @LastName,
BirthDate = @BirthDate,
Sex = @Sex,
Weight = @Weight,
SecurityId = @SecurityId
where PersonId = @PersonId
if @@error = 0 begin
set @result = 0
end
return @result
go
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE apPersonInsert
@FirstName varchar(50),
@LastName varchar(50),
@BirthDate datetime,
@Sex char(1),
@Weight decimal,
@SecurityId uniqueidentifier,
@PersonId int output,
@AuditUserId int
AS
declare @result bit
set @result = -1
insert into [Person]( FirstName, LastName, BirthDate, Sex, Weight,
SecurityId )
values ( @FirstName, @LastName, @BirthDate, @Sex, @Weight, @SecurityId
)
if @@error = 0 begin
set @PersonId = scope_identity()
set @result = 0
end
return @result
go
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
It runs fine in query analyzer, but when i try it via the command
object, i get errors about @result already being declared and syntax
error near create procedure.
Any ideas?