 |
SoftTree Technologies
Technical Support Forums
|
|
Author |
Message |
Mindflux
Joined: 25 May 2013 Posts: 846 Country: United States |
|
12.3.427: Help with code snippet / macro |
|
In relation to the trigger post I made a minute ago:
 |
 |
DISABLE TRIGGER $OBJECT(trigger, ins_object)$ ON $OBJECT(table, ins_object)$; |
outputs something like
 |
 |
DISABLE TRIGGER TABLA_UTrig ON TABLA_UTrig; |
Is there a way to make the object/table part of the macro seek out the owner of the trigger?
Since my naming conventions are solid enough this code does work:
 |
 |
DISABLE TRIGGER $OBJECT(trigger, ins_object)$ ON $$ SELECT LEFT('$OBJECT(trigger, ins_object)$',CHARINDEX('_','$OBJECT(trigger, ins_object)$')-1) $$ |
which then outputs
 |
 |
DISABLE TRIGGER TABLEA_UTRIG ON TABLEA; |
Right now since my naming conventions are fine.. though I may change that to use sys.tables joined to sys.triggers instead.
BUT really, the question is: is there a way to make $OBJECT(table,ins_object)$ smarter regarding this? Am I missing some simple way of doing this without the custom macro?
|
|
Fri May 05, 2023 12:17 pm |
|
 |
Mindflux
Joined: 25 May 2013 Posts: 846 Country: United States |
|
|
|
 |
 |
DISABLE TRIGGER $OBJECT(trigger, ins_object)$ ON $$ SELECT t.NAME FROM sys.tables AS t INNER JOIN sys.triggers AS t2 ON t2.parent_id = t.object_id WHERE t2.name = '$OBJECT(trigger, ins_object)$' $$
|
ENABLE TRIGGER $OBJECT(trigger, ins_object)$ ON $$ SELECT t.NAME FROM sys.tables AS t INNER JOIN sys.triggers AS t2 ON t2.parent_id = t.object_id WHERE t2.name = '$OBJECT(trigger, ins_object)$' $$ |
This works good and will not break if for some reason my naming convention changes...
|
|
Fri May 05, 2023 12:21 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
After reading your initial post I was about to suggest a similar thing, use $$..$$ to create the final output.
|
|
Fri May 05, 2023 2:32 pm |
|
 |
Mindflux
Joined: 25 May 2013 Posts: 846 Country: United States |
|
|
|
 |
 |
After reading your initial post I was about to suggest a similar thing, use $$..$$ to create the final output. |
So at this time $OBJECT(...)$ cannot resolve dependencies/parents/children in any meaningful way?
|
|
Fri May 05, 2023 2:33 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
 |
 |
So at this time $OBJECT(...)$ cannot resolve dependencies/parents/children in any meaningful way? |
Not that as far as triggers and tables go. If there are several macros bound to a single table select, or column selection for table, it can handle that. But parents and children it cannot tie together.
|
|
Fri May 05, 2023 5:56 pm |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|