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.
| Author |
Topic |
|
Brittney10
Posting Yak Master
154 Posts |
Posted - 2011-06-16 : 15:12:52
|
I use the SYSTEM_USER built-in function to capture who edited a record in several of my SQL tables. However, the domain name is put at the beginning of the username, such as FNC/Brittney for example. I need to trim off those first 4 letters, so it just shows Brittney. Should I do that with a replace after it's been inserted, or what would be the best approach? Currently a trigger puts the username in there: ALTER TRIGGER [dbo].[TRIGGERNAME] ON [dbo].[TableA]FOR UPDATE ASbeginupdate TableA set Modified_By = SYSTEM_USER FROM TableA A join INSERTED i on A.id= i.idend |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2011-06-16 : 15:23:43
|
| might be better to do it at insertion. if you do it after the fact you might get into a cyclical thing where now your trigger runs again and again.I would use SUBSTRING with PATINDEX and allIf you don't have the passion to help people, you have no passion |
 |
|
|
Brittney10
Posting Yak Master
154 Posts |
Posted - 2011-06-16 : 15:29:02
|
I'm wondering why this doesn't work. ALTER TRIGGER [dbo].[TRIGGERNAME] ON [dbo].[TableA]FOR UPDATE ASbeginupdate TableA set Modified_By = replace(SYSTEM_USER, 'FNC/', '')FROM TableA A join INSERTED i on A.id= i.idend |
 |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2011-06-16 : 16:33:46
|
| should work depends what it is that you are doing in that joinIf you don't have the passion to help people, you have no passion |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-06-16 : 17:20:30
|
| ALTER TRIGGER [dbo].[TRIGGERNAME] ON [dbo].[TableA]FOR UPDATE ASbeginupdate TableA set Modified_By = replace(SYSTEM_USER, 'FNC\', '')FROM TableA A join INSERTED i on A.id= i.idendJimEveryday I learn something that somebody else already knew |
 |
|
|
|
|
|