The following code demonstrates the processing of generating a date number. The total number of numbers is 8. The top 5 is the a

xiaoxiao2021-03-05  45

- The following code demonstrates the processing of generating a date number, the total number of numbers is 8, the top 5 is the annual monthly information, the format is YYMM, the last 4 is the water number. - Create a view of the current date Create View V_Getdateasselect Dt = Convert (Char (4), Getdate (), 12) GO

- Get a new number of function crete function f_nextbh () returns char (8) asbegin declare @dt char (4) SELECT @ DT = DT from v_getdate return (select @ DT Right (10001 ISNULL (Right (Max (BH) , 4), 0), 4) from TB with (Xlock, PAGLOCK) Where Bh Like @dt '%') EndGo

- Application Function Create Table TB (BH CHAR (8) Primary Key Default DBO.F_NEXTBH (), COL INT)

- Insert Information INSERT TB (COL) VALUES (1) Insert TB (Col) VALUES (2) Insert TB (Col) Values ​​(3) Delete TB Where Col = 3Insert TB (Col) VALUES (4) Insert TB (BH, COL) VALUES (dbo.f_nextbh (), 14)

- Display result Select * from tb / * - Results Bh col -------- ----------- 05040001 105040002 205040003 405040004 14

(The number of rows affects is 4 lines) - * / GO

DROP TABLE TBDROP FUNCTION F_NEXTBHDROP View V_Getdate

转载请注明原文地址:https://www.9cbs.com/read-36522.html

New Post(0)