需要生成这样的序列号,前半部分是yyyymmdd格式的年月日时间数字,后半部分则是每天都从1顺序增长的数字,位数要固定,中间不足的补0。在SQL Server 2000测试通过如下代码,功能已经实现,不过看起来太臃肿复杂,不知有无更简便的方法。
USE
MASTER
GO
IF EXISTS ( SELECT * FROM dbo.sysdatabases WHERE name = ' my_test_database ' )
DROP DATABASE [ my_test_database ]
GO
CREATE DATABASE [ my_test_database ]
GO
USE [ my_test_database ]
GO
CREATE TABLE [ my_table ] ( [ my_id ] VARCHAR ( 16 ))
GO
-- 存储过程开始
CREATE PROCEDURE get_new_id
@NEW_ID VARCHAR ( 16 ) OUTPUT
AS
BEGIN
DECLARE @DATE DATETIME
DECLARE @YYYY VARCHAR ( 4
GO
IF EXISTS ( SELECT * FROM dbo.sysdatabases WHERE name = ' my_test_database ' )
DROP DATABASE [ my_test_database ]
GO
CREATE DATABASE [ my_test_database ]
GO
USE [ my_test_database ]
GO
CREATE TABLE [ my_table ] ( [ my_id ] VARCHAR ( 16 ))
GO
-- 存储过程开始
CREATE PROCEDURE get_new_id
@NEW_ID VARCHAR ( 16 ) OUTPUT
AS
BEGIN
DECLARE @DATE DATETIME
DECLARE @YYYY VARCHAR ( 4