单据对应的表--通过存储过程得到单据所有表原创
106人赞赏了该文章
556次浏览
编辑于2024年06月02日 13:00:22
1、执行存储过程,得到销售订单所有对应表,如图
2、存储过程
if(OBJECT_ID('Proc_GetTableName') is not null) begin drop proc Proc_GetTableName end go --创建存储过程 Create Procedure Proc_GetTableName ( @FormId varchar(100) ) as begin --表名变量 Declare @FTbName varchar(100); --临时表 Create table #TableNameTemp ( FTbName nvarchar(100) , FIndex int ) if(@FormId is not null) begin --直接找表名节点 insert into #TableNameTemp(FTbName,FIndex) select Item.value('text()[1]','nvarchar(100)') tbName , ROW_NUMBER() OVER(ORDER BY Item) AS FIndex from (select CAST(FKernelXML as XML) fxml from T_META_OBJECTTYPE where FID=@FormId) tt cross apply tt.fxml.nodes('//TableName') as tb(Item) --查询所有的表名中的拆分表 Declare @MaxIndex int =1; select @MaxIndex = MAX(FIndex) from #TableNameTemp while(@MaxIndex >0) begin select @FTbName = FTbName from #TableNameTemp where FIndex = @MaxIndex; insert into #TableNameTemp(FTbName,FIndex) select tbName,0 from ( select @FTbName+'_'+ Item.value('text()[1]','nvarchar(100)') as tbName from (select CAST(FKernelXML as XML) fxml from T_META_OBJECTTYPE where FID='SAL_SaleOrder') tt cross apply tt.fxml.nodes('//SplitTables/SplitTable/Suffix') as tb(Item)) tb1 where object_id(tb1.tbName) is not null; --下一次循环表索引 set @MaxIndex = @MaxIndex- 1; end --多选基础资料的表 --一些特殊的表 end select FTbName from #TableNameTemp end
赞 106
106人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
您的鼓励与嘉奖将成为创作者们前进的动力,如果觉得本文还不错,可以给予作者创作打赏哦!
请选择打赏金币数 *
10金币20金币30金币40金币50金币60金币
可用金币: 0