存储过程生成ID [英] store procedure generate ID

查看:114
本文介绍了存储过程生成ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有一张桌子,上面有一些colom
ID,名字,姓氏
我要在插入此表时创建存储过程
id自动生成为L110000001BCA,L110000002BCA,L110000003BCA

thx每个人

hello all

i have a table with some colom
id, firstname, lastname
i want to create store procedure when insert in this table
id automatic generate like this L110000001BCA , L110000002BCA , L110000003BCA

thx everyone

推荐答案

检查以下链接

让我们测试一下

let test this

Create Procedure InsData @FirstName varchar(50), @LastName varchar(50)
As
Begin
    Declare @id int
    Select @id=max(CAST(SUBSTRING(id,2,9) as Int)) from TableName
    Insert into TableName(id,firstname,lastname)
    Values('L'+CAST((@id+1) as varchar(10)+'BCA',@FirstName,@LastName)
End


为什么输出是L112BCA而不是L110000002BCA ???

谁能帮助我
why the output is L112BCA, not L110000002BCA ???

can anybody help me


这篇关于存储过程生成ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆