title: Getting current user with a sql trigger
body: <p>I have the following sql trigger for one of my tables. I'm just wondering if its possible that i can track and add the user that makes a change to the table?</p>
  
  <p>See code below</p>
  
  <pre><code>ALTER trigger [dbo].[Trigger_Audit_Client] on [dbo].[Client] for insert, update, delete
  as
  declare @type varchar(1) ,
  @UpdateDate datetime
  
  if exists (select * from inserted) and exists (select * from deleted)
      select @type = 'U'
  else if exists (select * from inserted)
      select @type = 'I'
  else
      select @type = 'D'
  
  select  @UpdateDate = getdate()
  
  insert  Client_Audit (Client_Id, ClientName, ClientSurname, TelephoneHome, TelephoneWork, TelephoneCellular, DOB, Gender, ClientIdNumber, Company_Id, Region, City, Email, AddressLine1, AddressLine2, Will_UID, WillCreated, WillLatest, UpdateDate, UpdateType)
  select  Client_Id, ClientName, ClientSurname, TelephoneHome, TelephoneWork, TelephoneCellular, DOB, Gender, ClientIdNumber, Company_Id, Region, City, Email, AddressLine1, AddressLine2, Will_UID, WillCreated, WillLatest, @UpdateDate, @type + '_old'
  from deleted
  insert  Client_Audit (Client_Id, ClientName, ClientSurname, TelephoneHome, TelephoneWork, TelephoneCellular, DOB, Gender, ClientIdNumber, Company_Id, Region, City, Email, AddressLine1, AddressLine2, Will_UID, WillCreated, WillLatest, UpdateDate, UpdateType)
  select  Client_Id, ClientName, ClientSurname, TelephoneHome, TelephoneWork, TelephoneCellular, DOB, Gender, ClientIdNumber, Company_Id, Region, City, Email, AddressLine1, AddressLine2, Will_UID, WillCreated, WillLatest, @UpdateDate, @type + '_new'
  from inserted
  </code></pre>