pull out username

  • we are inserting into table system_user for createdby column.

    the data that is being inserted is 'DOMAIN\username'

    we just need the username and not the domain name

    i have used the following code.

    CREATE TABLE X (A VARCHAR(20))

    Declare @final varchar(20),@len int;

    select @final=(system_user);

    set @len = patindex('%\%', @final) +1;

    select @len;

    insert into x values (substring(@final,@len,20))

    select * from X

    is there an easier way to approach this?

    thanks

    Noli Timere
  • Here's how I'd do it:

    create table x (A varchar(20))

    insert into x

    select substring(system_user,charindex('\',system_user) + 1,20)

    select * from x

    You can decide if it seems easier.

    Greg

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply