cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Alexey
Engaged Sweeper
Hi!
Can I specify the "last logon" variable of the user in the description of a specific computer?

For example, I have a "pc-20-18" computer with AssetID = 516. The last logged in user on it is always the same, because this is his personal corporate PC. Can I use a variable or key for this asset in the description field?
21 REPLIES 21
Alexey
Engaged Sweeper
Then the entire script, taking into account the adjustments, will look like this:

CREATE TRIGGER mytrigger ON [tblAssets]
AFTER UPDATE AS
BEGIN
SET NOCOUNT ON;
Update [tblAssets]
Set [Description] = [Description] + ' used by ' + Userdomain + '\' + Username
where Userdomain is not null and Username is not null and Description not like '% used by ' + Userdomain + '\' + Username + '%'
END


Ok, thanks a lot! 🙂
Alexey
Engaged Sweeper
Thanks again! I will definitely try it soon.
(I hope nothing breaks ;D)
prighi61
Engaged Sweeper III
Alexey T wrote:
Thanks again! I will definitely try it soon.
(I hope nothing breaks ;D)


I forgot to suggest to add a:
SET NOCOUNT ON;

statement just under the BEGIN line.

To remove the trigger just execute the SQL command:

Drop trigger mytrigger.

Maybe you could test the update statement as a script, in advance, after taken a DB backup 😉
Alexey
Engaged Sweeper
Now I understand. I will try.
And shouldn't this part of the condition (where... and Description not like '% used by ' + Userdomain + '\' + Username) prohibit updating these descriptions if one owner is already indicated there?
prighi61
Engaged Sweeper III
Alexey T wrote:
Now I understand. I will try.
And shouldn't this part of the condition (where... and Description not like '% used by ' + Userdomain + '\' + Username) prohibit updating these descriptions if one owner is already indicated there?


To prevent that you should slightly modify it into (add a '%' to the end):

where Userdomain is not null and Username is not null and Description not like '% used by ' + Userdomain + '\' + Username + '%'

so that it can be found even in the middle of the description.
Alexey
Engaged Sweeper
Everything is fine. 🙂
Thanks for the suggested solution, but I just didn't understand where to create this trigger? In the web interface, I can create reports using SQL, but this trigger obviously does nothing there. Forgive me not my knowledge, I am still far from being with SQL. 😞
prighi61
Engaged Sweeper III
Alexey T wrote:
Everything is fine. 🙂
Thanks for the suggested solution, but I just didn't understand where to create this trigger? In the web interface, I can create reports using SQL, but this trigger obviously does nothing there. Forgive me not my knowledge, I am still far from being with SQL. 😞


You have to add it to the SQL database. You'd better use SQL Server Management Studio and open a new Query window where paste the SQL command to, select the lansweeper database and execute it.

Be aware that every time the last user changes, it will be appended (not replacing the previous one).
Alexey
Engaged Sweeper
Oh.
Thanks, but I'm confused. 🙂
At first you seemed to be talking about a trigger, now about a script. I don't know where to run it yet.
prighi61
Engaged Sweeper III
Alexey T wrote:
Oh.
Thanks, but I'm confused. 🙂
At first you seemed to be talking about a trigger, now about a script. I don't know where to run it yet.


I'm sorry I used the term script, but I should have used the term statement. The trigger should be like this:

CREATE TRIGGER mytrigger ON [tblAssets]
AFTER UPDATE AS
BEGIN
Update [tblAssets]
Set [Description] = [Description] + ' used by ' + Userdomain + '\' + Username
where Userdomain is not null and Username is not null and Description not like '% used by ' + Userdomain + '\' + Username
END
Alexey
Engaged Sweeper
Hi, prighi61!
Thx for answer.
What trigger? Where and how to set it up? Have an article?