views:

1821

answers:

3

I have the following table:

Table A
FNAME | LNAME
james | Bond
John  | Brit
raje  | van

I want to insert first letter from first column with full last name to create a new username column for the table:

Table A
USERNAME
jbond
jbrit
rvan

If this is not possible, I at least need to update the lastname from lname to newly created username column and to set a default password for all the rows

+4  A: 

Add new column username:

ALTER TABLE tableA ADD username varchar(50) 
-- 50 is an example, it should be choosed depending on data

then execute this query:

UPDATE tableA
SET username = LEFT(fname, 1) + lname
najmeddine
how do i check whether the username is unique.
jero
+1  A: 
UPDATE TableA SET username = SUBSTRING(fname,1,1) + lname
Lukasz Lysik
+1  A: 

Consider using a computed column (or persisted computed column or even an indexed persisted computed column).

References:

Rob Garrison