SQL Server 存储过程自定义生成ID号

 IF EXISTS(SELECT TOP 1 * FROM sys.tables WHERE name=N'EmployeeNo_Identity')
DROP TABLE EmployeeNo_Identity
GO CREATE TABLE EmployeeNo_Identity(
ID BIGINT NOT NULL IDENTITY(1000000,1) PRIMARY KEY,
CreateDate DATETIME DEFAULT(GETDATE())
) IF EXISTS(SELECT TOP 1 * FROM SYS.procedures WHERE name=N'proc_Build_Employee_ID')
DROP PROC proc_Build_Employee_ID
GO CREATE PROC proc_Build_Employee_ID
@prefix NCHAR(1),
@result nvarchar(8) OUT
AS
BEGIN
DECLARE @id BIGINT
INSERT INTO EmployeeNo_Identity(CreateDate) VALUES(GETDATE())
SELECT @id=MAX(ID) FROM EmployeeNo_Identity NOLOCK
DELETE EmployeeNo_Identity
SET @result=CAST( @prefix+CONVERT(NVARCHAR(7),@id) AS NVARCHAR(8))
END
GO /** 调用 **/
DECLARE @result NVARCHAR(8)
EXEC [dbo].[proc_Build_Employee_ID]
@prefix = N'E',
@result=@result OUT
SELECT @result
上一篇:【经验】PHP开发中  导致页头一行空白


下一篇:HTML页面顶部出现空白部分(#65279字符?)解决办法