ERP基础档案管理模块中实现多级分类档案ID号自动编码技术(V1.0)

来源:互联网 发布:网络视频帧数是多少 编辑:程序博客网 时间:2024/05/16 03:25
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

   

ERP基础档案管理模块中实现多级分类档案ID号自动编码技术(V1.0)

 

   本存储过程实现了多级分类档案ID号自动编码技术,本版本(V1.0)现在只实现每级3位的编码,

本版本的特点是:

n         可以根据不同的表产生不同的编码,达到通用化

n         调用时通过指定iIsSubNode要产生的节点编码是否是子结点还是兄弟节点来生成对应编码

进行调用本存储过程时需要注意的是需要传递节点的层次(或是叫节点的深度)

另外下一个版本(V2.0)将根据用户自定义每级长度来实现更灵活的自动编码技术。

 

CREATEprocedureprcIDAutoGen

@vSourceIDvarchar(30),

@IDepthint,

@iIsSubNodeint,

@Tablevarchar(20),

@vIncrementvarchar(30)output

as

begin

declare@iLenint

declare@vTempIDvarchar(30)

declare@SQLStringnvarchar(500)

if@iIsSubNode=1

begin

 set@IDepth=@IDepth+1

 set@iLen=@IDepth*3

 set@SQLString=N'selectvIDfrom'+@Table+'wherevID='''+ltrim(rtrim(@vSourceID))+''''

 exec(@SQLString)

 if@@rowcount>0

 begin

 select@vSourceIDasvIDinto#t

 set@SQLString=N'insert#tselectvIDfrom'+@Table+'wherevParentIDin(selectvIDfrom#t) andvIDnotin(selectvIDfrom#t)andIDepth=@IDepth'

 execsp_executesql@SQLString,N'@IDepthint',@IDepth

 if@@rowcount>0

 begin

  set@SQLString=N'select   @vTempID=isnull(max(vID),''0'')from#t'

  execsp_executesql@SQLString,N'@vTempIDvarchar(30)output',@vTempID output      

  set@SQLString='select@vIncrement=right(''000''+cast((cast(substring(@vTempID,1,@iLen)asdecimal(30,0))+1)asvarchar),@iLen)'

  execsp_executesql@SQLString,N'@vIncrementvarchar(30)output,@vTempIDvarchar(30),@iLenint',@vIncrementout,@vTempID,@iLen

 end

 else

 begin

  select        @vIncrement=ltrim(rtrim(@vSourceID))+'001'

 end

 end

 else

 begin

 select@vIncrement='001'

 end

end

else

begin

 set@iLen=len(ltrim(rtrim(@vSourceID)))

 set@SQLString=N'selectvIDfrom'+@Table+'wherevID='''+ltrim(rtrim(@vSourceID))+''''

 exec(@SQLString)

 if@@rowcount>0

 begin

  set@SQLString=N'select @vTempID=isnull(max(vID),''0'')from'+@Table+'wherevIDin(selectvIDfrom'+@Table+'whereIDepth=@IDepth)'

  execsp_executesql@SQLString,N'@vTempIDvarchar(30)output,@IDepthint',@vTempID output,@IDepth    

  set@SQLString='select@vIncrement=right(''000''+cast((cast(substring(@vTempID,1,@iLen)asdecimal(30,0))+1)asvarchar),@iLen)'

  execsp_executesql@SQLString,N'@vIncrementvarchar(30)output,@vTempIDvarchar(30),@iLenint',@vIncrementout,@vTempID,@iLen

 end

 else

 begin

  select@vIncrement='001'

 end

end

end

 

用户创建基础档案时可以按以下类似表格式创建:

createtableCustomerClass(

vID   varchar(30)constraintpkCustomerClassprimarykey,1<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击