二开案例.数据库.获取种子值(单据)
【应用场景】
非插件使用场景下,新增单据时,获取单据相关数据表的种子值。
【示例代码】
以采购订单为例,获取采购订单主表(单据头表)T_PUR_POOrder的种子值的SQL脚本如下:
【SQL Server账套】
/*dialect*/ DECLARE @count INT; -- 这里设置要获取的种子值的数量 SET @count = 1; DECLARE @icount INT; SET NOCOUNT ON; SET @icount = 0; DECLARE @OutIdTable TABLE ( Id BIGINT ); DECLARE @lastValue INT; DECLARE @trancount INT; SET @trancount = @@TRANCOUNT; IF @trancount > 0 SAVE TRANSACTION sp; ELSE BEGIN TRANSACTION; BEGIN TRY IF @count <= 100 BEGIN WHILE @icount < @count BEGIN INSERT INTO Z_PUR_POOrder ( Column1 ) VALUES ( 0 -- Column1 - int ); INSERT INTO @OutIdTable ( Id ) VALUES ( SCOPE_IDENTITY() ); SET @icount = @icount + 1; END; SELECT Id FROM @OutIdTable; END; ELSE BEGIN UPDATE Z_PUR_POOrder WITH ( TABLOCK ) SET Column1 = Column1; EXEC sp_executesql N'insert into Z_PUR_POOrder(column1) select top(@count) 1 from master..spt_values x cross join master..spt_values y cross join (select top 200 * from master..spt_values) n', N'@count int', @count = @count; SELECT Id FROM Z_PUR_POOrder WITH ( TABLOCK ); END; IF @trancount > 0 ROLLBACK TRANSACTION sp; ELSE ROLLBACK TRANSACTION; END TRY BEGIN CATCH IF @trancount > 0 ROLLBACK TRANSACTION sp; ELSE ROLLBACK TRANSACTION; DECLARE @errmessage NVARCHAR(4000); DECLARE @errserverity INT; DECLARE @errstate INT; SELECT @errmessage = ERROR_MESSAGE() , @errserverity = ERROR_SEVERITY() , @errstate = ERROR_STATE(); RAISERROR(@errmessage,@errserverity,@errstate); END CATCH;
【Oracle账套】
/*dialect*/ SELECT Z_PUR_POOrder.nextval AS fkey FROM dual CONNECT BY LEVEL<=1
---------------------------------------------------------------------------------------------------------
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.数据库.获取种子值(单据)
【应用场景】非插件使用场景下,新增单据时,获取单据相关数据表的种子值。【示例代码】以采购订单为例,获取采购订单主表(单据头表)T_PU...
点击下载文档
本文2024-09-23 03:58:49发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-162331.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章