What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 225 |  Welcome, Guest!   Register  Login
 Home > Forums > Sql Server > how to create EMP01 like Emp idin sql server 2005 ...
Reddysankark@Yahoo.Com

how to create EMP01 like Emp idin sql server 2005

Replies: 7 | Posted by: Reddysankark@Yahoo.Com on 10/26/2012 | Category: Sql Server Forums | Views: 385 | Status: [Member] | Points: 10  


hi,

how to create EMP01 like Emp id in sql server 2005 or in ASp.net

sankarreddy


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Santhi
Santhi  
Posted on: 10/27/2012 2:54:19 AM
Level: Starter | Status: [Member] | Points: 25

Hi,

First, you have to create the ID in asp.net:
int i = 1;
string ID= "Emp" + i;
insert this value in the Employee ID column .
Now you can autogenerate the employee code.
select isnull(max(right(nvrempcode,3)),0)+1 as nvrempcode from tablename.
If you have any doubts, ask me.

Thanks && Regards,
V. Santhi.

Thanks & Regards,
Santhi .V

Reddysankark@Yahoo.Com, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reddysankark@Yahoo.Com
Reddysankark@Yahoo.Com  
Posted on: 10/27/2012 3:58:26 AM
Level: Starter | Status: [Member] | Points: 25

hi, i didn't get this.could you please explain with example

sankarreddy

Reddysankark@Yahoo.Com, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Santhi
Santhi  
Posted on: 10/27/2012 4:01:34 AM
Level: Starter | Status: [Member] | Points: 25

Hi,

Tell me your question clearly.
I will explain you according to that with an example.

Thanks && Regards,
V. Santhi

Thanks & Regards,
Santhi .V

Reddysankark@Yahoo.Com, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reddysankark@Yahoo.Com
Reddysankark@Yahoo.Com  
Posted on: 10/27/2012 11:05:28 AM
Level: Starter | Status: [Member] | Points: 25

Hi,

I need coding for EMP will be my prefix and number will digit start with 0001.my First registered user id will be this EMP0001.Anthoner Employee registraion Id will be EMP0002.How to this in C# or sql server 2005

sankarreddy

Reddysankark@Yahoo.Com, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Santhi
Santhi  
Posted on: 10/28/2012 7:34:34 AM
Level: Starter | Status: [Member] | Points: 25

Hi,

First time you time you have to generate the ID as EMP0001.

For Example : Get this value in a string.
first time check whether there is a record in the database by using the query.

Query = "select * from tablename.
Get the values in a datatable.
if the count value is equal to zero
then follow the following step:
if(dt.rows.count == 0)
{
string strID = "EMP0001";
}

Insert this value in the Employee ID column.
so, Next time the value will not be equal to zero.
If this value has been inserted in the table, you have to use the following query to autogenerate the ID.


select isnull(max(right(nvrempcode,4)),0)+1 as nvrempcode from tablename.
This query will autogenerate the ID.


Thanks && Regards,
V. Santhi.



Thanks & Regards,
Santhi .V

Reddysankark@Yahoo.Com, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Naraayanan
Naraayanan  
Posted on: 11/5/2012 3:50:11 AM
Level: Starter | Status: [Member] | Points: 25

Hi,
try this way

Query:
 Select max(empid) from tbl_employee_master

Store max of EmpId in string.
Split a string using string array.
Eg:
string empId ="EMP0001";

string spiId[] = emplId.Split('p');
Now,
You get
  splid [1] = 0001;

Now , you Increase a value like this
int currentId = Convert.Toint32(splid[1]) +1;

and
concanate with Prefix value
string lastId= "EMP" + Convert.ToString(currentId )



Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Reddysankark@Yahoo.Com, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Sourabh07
Sourabh07  
Posted on: 11/6/2012 12:27:10 AM
Level: Starter | Status: [Member] | Points: 25

hi..to all

please try the following code as an example........

and edit it accordingly.............

Create table #temp 

(
pk_id int identity,
empcode varchar(50) default 'EMP',
empname varchar(50)
)

Insert into #temp (empname) values('A')

Declare @empcode varchar(10)

set @empcode = @@IDENTITY

while Len(@empcode) < 5
begin

set @empcode = '0' + @empcode

end

Update #temp
set empcode = empcode + cast(@empcode as varchar)
where pk_id=@@identity

Select * from #temp

drop table #temp


Sourabh07

Reddysankark@Yahoo.Com, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 8:34:54 PM