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

推荐订阅源

云风的 BLOG
云风的 BLOG
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
月光博客
月光博客
人人都是产品经理
人人都是产品经理
宝玉的分享
宝玉的分享
博客园 - 司徒正美
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
Vercel News
Vercel News
T
The Blog of Author Tim Ferriss
T
Tailwind CSS Blog
A
About on SuperTechFans
Apple Machine Learning Research
Apple Machine Learning Research
L
LangChain Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
Visual Studio Blog
S
SegmentFault 最新的问题
Google DeepMind News
Google DeepMind News
博客园 - 聂微东

博客园 - 世之云枭

网站技术分享 网页内容抓取 推广:湖南省德谦新材料有限公司 Http://www.paint123.cn CentOS MySQL安装和编译【转帖】 缓存容器类的实现(C#) ReadFreeCache 设计一个高效的网络服务器用户管理类 修改自增字段 C++、Java与C#的命名规范总结 (转) VTL-vm模板的变量用法 - 世之云枭 - 博客园 http://www.cnblogs.com/onlytiancai/archive/2009/04/11/1433456.html 数据库中与c#中的数据类型对照 - 世之云枭 - 博客园 SessionID的正确说明 临时文件 细节决定成败 NVelocity 主从表 自动生成清空数据库的SQL语句 自动生成Insert数据的SQL脚本 分页存储过程
常用的获取最大值
世之云枭 · 2008-07-07 · via 博客园 - 世之云枭

-------------------表
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Code]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Code]
GO

CREATE TABLE [dbo].[Code] (
 [id] [int] IDENTITY (1, 1) NOT NULL ,
 [code] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
 [codenumber] [bigint] NULL ,
 [info] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO

/*
这个存储过程主要是用来生成各种各样的单号的。传入一个特别码单号来分清他对应的是那一个类型单号的最大值
*/
create        PROCEDURE [dbo].[addmaxsto] @Code varchar(20) ,@ouototal varchar(50)='' output AS
declare @orderidcard varchar(14)
declare @temp varchar(50)
if (select  left(codenumber,8)  from  code where code=@Code)=(select convert(varchar(8),getdate(),112))--如果是同一天
  begin
    UPDATE code SET codenumber =codenumber +1 where code=@Code    --在原来的单号上加1
  end
else
  begin
     set @orderidcard=(cast((select convert(varchar(8),getdate(),112))as varchar(50)))+'00001' --生成单的编号
     UPDATE code SET codenumber =@orderidcard where code=@Code
  end

 select top 1 @ouototal=codenumber   from (select * from  code where code=@Code)  

output

GO