sql Carregamento Estruturas MRS

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql Carregamento Estruturas MRS相关的知识,希望对你有一定的参考价值。

CREATE TABLE #ExternalCodeTemp (RowID int IDENTITY(1, 1), HierarchicalStructureId varchar(18) NOT NULL)

INSERT INTO #ExternalCodeTemp
SELECT HierarchicalStructureId FROM ra.HierarchicalStructure hie WHERE hie.HierarchyLevel='UNB' AND ExternalCode IS NULL 

DECLARE @HierarchicalStructureId varchar(18)
DECLARE @NumberRecords int = @@ROWCOUNT
DECLARE @RowCount int = 1

WHILE @RowCount <= @NumberRecords
BEGIN
 SELECT @HierarchicalStructureId = HierarchicalStructureId FROM #ExternalCodeTemp WHERE RowID = @RowCount

 SELECT * INTO #ExternalCodeTempAux
 FROM SplitString(@HierarchicalStructureId, '.')  
 WHERE zeroBasedOccurance>0

 DECLARE @SQLStr VARCHAR(18) 
 SET @SQLStr='' 
 SELECT @SQLStr=@SQLStr+'.'+[a].[Column] FROM 
 (SELECT CONVERT(VARCHAR(2),s)as[Column] FROM #ExternalCodeTempAux --ORDER BY zeroBasedOccurance
  )AS a 
 SET @SQLStr=RIGHT(@SQLStr,len(@SQLStr)-1)

 UPDATE ra.HierarchicalStructure SET ExternalCode = @SQLStr WHERE HierarchicalStructureId = @HierarchicalStructureId

 DROP table #ExternalCodeTempAux 

 SET @RowCount = @RowCount + 1
END
 
DROP TABLE #ExternalCodeTemp

以上是关于sql Carregamento Estruturas MRS的主要内容,如果未能解决你的问题,请参考以下文章

SQL*Plus中怎么执行多个*sql脚本文件

sql 2008和sql 2012的区别

sql [sql技巧]一些sql技巧#sql

sql 2008 r2 在sql 2008上兼容么

SQL基础

有大神知道,sql server 中如何批量执行sql语句吗?