日期:2014-05-17 浏览次数:20536 次
CREATE TABLE t1
(
riqi DATE,
code VARCHAR(12)
)
INSERT INTO t1
SELECT CURRENT_TIMESTAMP,CONVERT(VARCHAR(8),CURRENT_TIMESTAMP,112)+'0001'
SELECT * FROM t1
INSERT INTO t1
SELECT CURRENT_TIMESTAMP
,CONVERT(VARCHAR(8),CURRENT_TIMESTAMP,112)+RIGHT('00000000'+LTRIM(MAX(CAST(RIGHT(code,4) AS INT))+1),4)
FROM t1
WHERE riqi=CONVERT(VARCHAR(10),CURRENT_TIMESTAMP)
riqi code
2012-12-11 201212110001
2012-12-12 201212120001
2012-12-11 201212110002
2012-12-11 201212110003
2012-12-11 201212110004
2012-12-11 201212110005