Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Take some data part from all column !!

Author  Topic 

ashu1234
Starting Member

9 Posts

Posted - 2009-04-11 : 13:02:24
Hello All !!!
I m try to doing, i have one table emp_dtl in this table all the column is belongs to employee details...
like

Emp_Name Emp_userid emp_password Address Phone
Ashwani ashwani11 123 New Delhi 9211556623
Rahul rahul321 10000 Australia 9212000000
kamal kamalkk2 10000 Pakistan 9800000000
kiran kiran001 123 Brazil 9811111111
ishu eshu123 111 New Zeland 9222222222


I want to create one Employee_ID column in this column
employee_id nvarchar (20)
and this column contain some part of emp_username, user_id, password, address and finally phone and this is unique id (it should be unique)
because this is automatic generated key...


like answer is ash+ni+123+new+6623=== ashni123new6623 (Unique key)
and this key automatic stored in database in same table (emp_datils)


help me

ashwani

ashwani

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-04-11 : 13:40:12
Well..you haven't given the logic behind generating the Employee_Id..but based on your example..something like this.

ALTER TABLE EmpDetails ADD Employee_Id nVARCHAR(20)

UPDATE EmpDetails
SET Employee_Id = LEFT(Emp_name,3) + LEFT(Emp_userid,3) + LEFT(emp_password,3) + LEFT(Address,3) + RIGHT(Phone,4)

Go to Top of Page

ashishashish
Constraint Violating Yak Guru

408 Posts

Posted - 2009-04-11 : 14:29:51
yes u can done this by method as vijayisonly stated above or if u just want unique number and not concerned about ur combination then use newid() for this purpose..
Thanks,,else use vijayisonlysolution
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-04-12 : 13:36:03
why dont you make employeeid column computed if its value is derived from other columns? if you want to store value in table then make it persisted.
Go to Top of Page
   

- Advertisement -