SQL 流水号 字符串主键
来源:互联网 发布:ubuntu安装vs2013 编辑:程序博客网 时间:2024/06/07 02:18
--Create by Ranen bolg:http://blog.csdn.net/ranen2010
--根据给定的编码比如Emp,生成一个字符串类型的流水号,如:20110102Emp0001
--建立表
CREATE TABLE PrimKey(
cDate datetime not null,
cChar varchar(3) not null,
cCount int not null
)
--创建主键的存储过程
Create Proc GetPrimKey
@char varchar(3),
@res nvarchar(15) output
As
Begin
declare @count int
begin try
select @count=isnull(cCount,0) from PrimKey where convert(varchar(8),cDate,112)=Convert(nvarchar(8),getdate(),112) and cChar=@char
set @count=isnull(@count,0);
if(@count>0)
begin
Update PrimKey set cCount=@count+1 where convert(varchar(8),cDate,112)=Convert(nvarchar(8),getdate(),112) and cChar=@char
end
if(@count<=0)
begin
Insert into PrimKey values(Convert(nvarchar(10),getdate(),21),@char,1);
end
set @res =Convert(nvarchar(8),getdate(),112)+@char+right('00000000'+convert(varchar(5),@count+1),4)
end try
begin catch
set @res='One Error';
end catch
End
--测试调用
declare @res nvarchar(20)
exec GetPrimKey 'Emp',@res output
print @res
- SQL 流水号 字符串主键
- SQL Server 自动 生成流水号 字符串主键
- SQL Server 自动生成字符串主键 流水号
- 主键ID流水号
- mybatis插入流水号主键
- SQL Server 生成带流水号的字符串
- SQL生成流水号
- SQL生成流水号
- sql 生成流水号
- SQL流水号
- SQL自动生成流水号
- SQL流水号生成语句
- 使用SQL创建流水号
- 日期、字符串、流水号处理应用举例
- SQL存储过程生成流水号
- SQL存储过程生成流水号
- 通过SQL自动添加流水号
- SQL学习----日期流水号生成
- WebClient does not support concurrent I/O operations 错误的解决办法
- 深度搜索与追girl
- Linq 好去处!
- windows 2003 服务器建站基础
- Ubuntu探秘之二:软件包管理系统
- SQL 流水号 字符串主键
- WP7 LinqToXml调用静态xml文件
- timer 定时器
- 对于CFile的不满~
- Ubuntu探秘之三:linux世界的大门----GRUB
- Fedora11修改为root权限
- __stdcall, __cdecl, __fastcall区别 (转载)
- Dijkstra
- linux内核bug调试指南(一)