惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
D
Docker
美团技术团队
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
宝玉的分享
宝玉的分享
月光博客
月光博客
J
Java Code Geeks
V
V2EX
IT之家
IT之家
T
Troy Hunt's Blog
D
DataBreaches.Net
Cloudbric
Cloudbric
Blog — PlanetScale
Blog — PlanetScale
H
Hackread – Cybersecurity News, Data Breaches, AI and More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
G
Google Developers Blog
MongoDB | Blog
MongoDB | Blog
The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
Google DeepMind News
Google DeepMind News
Engineering at Meta
Engineering at Meta
博客园 - Franky
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
H
Help Net Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
aimingoo的专栏
aimingoo的专栏
S
Security Affairs
Hugging Face - Blog
Hugging Face - Blog
Forbes - Security
Forbes - Security
AI
AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
腾讯CDC
H
Heimdal Security Blog
The Cloudflare Blog
S
SegmentFault 最新的问题
Google Online Security Blog
Google Online Security Blog
Webroot Blog
Webroot Blog
有赞技术团队
有赞技术团队
The Hacker News
The Hacker News
Microsoft Security Blog
Microsoft Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
罗磊的独立博客
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 聂微东
Help Net Security
Help Net Security
T
The Exploit Database - CXSecurity.com

博客园 - gz.net

gridview绑定问题 - gz.net - 博客园 jsp数据库大全 login Microsoft Windows SharePoint Services ASP.NET程序中常用代码汇总(一) - gz.net - 博客园 ASP.NET动态生成HTML页面 日语的初次认识 日语的初次认识 对于长时间装载的ASP.NET页面如何在客户端浏览器中显示进度? 检测远程URL是否存在的三种方法 ---转自孟子 Eclipse快速上手指南 自己动手用c#写控件 代价 五种提高 SQL 性能的方法 js教程 HTML教程 HTML教程 存储过程编写经验三 存储过程经验二
好久没来了。共享一个自动生成编号的存储过程
gz.net · 2006-06-25 · via 博客园 - gz.net

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER  procedure pGetNewKey
  @cTableName varchar(20) = 'tOrderForm',
  @cKeyField varchar(15) = 'cCode',
  @iKeyLength integer = 12,
  @cResult varchar(15) output
as
  declare @cCode varchar(20),@cMax varchar(20),@cSerial varchar(4), @cSQL varchar(150), @cZero varchar(8)

  create table #a(cMaxCode varchar(10) null)

  if @iKeyLength>10
  begin
    set @cZero=substring('000000000000000',1,@iKeyLength-8)
    set @cSQL=
      'insert into #a select max(substring('+@cKeyField+',9,4)) cMaxCode from '+@cTableName+
      ' where substring('+@cKeyField+',1,8)=convert(char(8),getdate(),112)'
    Exec(@cSQL)

    select @cMax = cMaxCode from #a
   
    if @cMax is null
      set @cMax = '0'

    set @cSerial = convert(varchar(4),convert(int,@cMax)+1)

    set @cCode=convert(char(8),getdate(),112)+stuff(@cZero,@iKeyLength-8+1-len(@cSerial),len(@cSerial),@cSerial)
  end
  else
  begin
    set @cZero=substring('000000000000000',1,@iKeyLength)
    set @cSQL=
      'insert into #a select max('+@cKeyField+') cMaxCode from '+@cTableName

    Exec(@cSQL)

    select @cMax = cMaxCode from #a  

    if @cMax is null
      set @cMax = '0'

    set @cSerial = convert(varchar(4),convert(int,@cMax)+1)

    set @cCode=stuff(@cZero,@iKeyLength+1-len(@cSerial),len(@cSerial),@cSerial)
  end

  set @cResult = @cCode

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO