如何在sql中自动生成EMPID

如何在sql中自动生成EMPID

本文介绍了如何在sql中自动生成EMPID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用过这段代码但是转换失败了怎么办?我需要增加每次注册执行并产生一致性





i used this code but convertion failed how to do ? i need increment every execution of registration and generate unicqidentity


select  'FHMS'  + max(SUBSTRING ( employeeId ,5 , 5 ))+1 as nextkey from employeemaster

推荐答案

Try this in C#,

SqlCommand cmd=new SqlCommand("select MAX(SUBSTRING(employeeId ,5,1000))+1 as NextKey from employeemaster",connectionstring);

SqlDataReader dr=cmd.ExecuteReader();

dr.Read();

if(dr.HasRows)
{
string str;

str="FHMS";

string id=str+dr[0].ToString();

dr.Close();
}


select 'FHMS'+ cast (max(cast(SUBSTRING( employeeId ,5, 5 )as int))+1 as nvarchar) as nextkey from employeemaster


select 'FHMS'+ cast (employeeId nvarchar) as thisKey from employeemaster



如果出于任何原因(即我想不出一个足够好的一个),你想在插入它之前知道下一个id会是什么,然后看看 []


这篇关于如何在sql中自动生成EMPID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-16 07:55