/****** Object: StoredProcedure [dbo].[sp_InsertEmployee] Script Date: 09/17/2012 23:28:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: 插入一条雇员数据
-- =============================================
CREATE PROCEDURE [dbo].[sp_InsertEmployee]
-- Add the parameters for the stored procedure here
@Name varchar,
@UserName varchar,
@Password varchar,
@Hierarchy char,
@EmployeeTypeID int,
@Sex varchar,
@Telphone varchar,
@CellPhone varchar,
@QQ varchar,
@Email varchar,
@Statue varchar,
@Remark varchar,
@ManagerID int,
@Regions varchar
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @ID int
declare @tempSql varchar
-- Insert statements for procedure here
if exists(select * from Employee where Name=@Name)
return 0
begin transaction
insert into [Employee](
[Name],[UserName],[Password],[Hierarchy],[EmployeeTypeID],[Sex],[Telphone],[CellPhone],[QQ],[Email],[Statue],[Remark],[ManagerID]
)values(
@Name,@UserName,@Password,@Hierarchy,@EmployeeTypeID,@Sex,@Telphone,@CellPhone,@QQ,@Email,@Statue,@Remark,@ManagerID
)
set @ID = @@IDENTITY
if exists(select * from Permission where ID=@ID)
begin
delete from Permission where EmployeeID=@ID
end
else
begin
set @tempSql='insert into Permission select '+str(@ID)+', '''+replace(@Regions,',','''union select '+str(@ID)+',''')+''''
exec(@tempSql)
end
if @@ERROR>0
begin
rollback transaction
end
else
begin
commit transaction
end
END
GO