SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Way to use $OBJECT(..)$ macro inside $PROMPT(..)?

 
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant View previous topic
View next topic
Way to use $OBJECT(..)$ macro inside $PROMPT(..)?
Author Message
Mindflux



Joined: 25 May 2013
Posts: 812
Country: United States

Post Way to use $OBJECT(..)$ macro inside $PROMPT(..)? Reply with quote
I'm trying to make a snippet that prompts for a table and then an index name. I'd like the index name to prefix with IX_TableName

Code:
$PROMPT(idx_name,What is the name of your index?,IX_$OBJECT(ins_object,table)$,INDEX NAME)$
CREATE INDEX $idx_name$ ON $OBJECT(ins_object, table)$(|)
WITH(FILLFACTOR=80, SORT_IN_TEMPDB=OFF)
GO



This is what I'm using for the prompt, but the default value takes most of it as a string literal but cuts off at the comma (presumably because it's parsing for parameters) and my prompt title becomes 'table' instead of 'INDEX NAME'.

Is there a way to make this work? I tried escaping the $'s with ^ (caret) but was not able to succeed.


Last edited by Mindflux on Sun May 07, 2023 10:52 pm; edited 1 time in total
Sun May 07, 2023 9:55 pm View user's profile Send private message
Mindflux



Joined: 25 May 2013
Posts: 812
Country: United States

Post Reply with quote
Well, well I got it with a $$..$$ macro instead.. though the positional (pipe) is being used as a literal.

*Edit: got this to work with more $$ .. $$ macros ... it aint pretty.

Code:
$$ SELECT 'CREATE INDEX IX_$OBJECT(ins_object,table)$_'$$|$$ SELECT ' ON $OBJECT(ins_object,table)$( $COLUMNS(vertical,nokeys)$ )
WITH(FILLFACTOR=80,SORT_IN_TEMPDB=OFF)' $$

Sun May 07, 2023 10:07 pm View user's profile Send private message
gemisigo



Joined: 11 Mar 2010
Posts: 2108

Post Reply with quote
I had asked this a few years back and I recall something about it not being possible due to the order of the evaluation of the macros ($$..$$ goes last, I guess). But I hope SysOp can elaborate.
Mon May 08, 2023 3:22 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7847

Post Reply with quote
That is still the case. An alternative for $PROMPT...$ is to use a list for the prompt instead of an edit box and populate that list with table names, though I personally don't think that will work well practically.

Another alternative is to mouse over table name, if it's already in the code (or Database Explorer if you use one), then click the Table name hyperlink in the balloon and click Indexes tab. that takes a few seconds only. You can then choose columns and options in a graphical dialog. You can also review definitions of the existing indexes right there which may help you with choosing columns for new indexes, as well as modify and drop existing indexes if you want to optimize them. You don't want to build or update indexes immediately, script to clipboard or script to editor are available, as well as scheduling.
Mon May 08, 2023 8:24 am View user's profile Send private message
gemisigo



Joined: 11 Mar 2010
Posts: 2108

Post Reply with quote
Now that's hilarious. It only took this many years for me to notice that I can click the table name in the popup. And even then not by accident...
Mon May 08, 2023 8:31 am View user's profile Send private message
Mindflux



Joined: 25 May 2013
Posts: 812
Country: United States

Post Reply with quote
gemisigo wrote:
Now that's hilarious. It only took this many years for me to notice that I can click the table name in the popup. And even then not by accident...


Every now and then when I have to dig out the SQL Assistant help PDF I always learn something new.

Last night I learned ctrl+alt+h will highlight the the nearest statement relative the cursor position. (left or upward, anyway)
Mon May 08, 2023 8:44 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7847

Post Reply with quote
gemisigo wrote:
Now that's hilarious. It only took this many years for me to notice that I can click the table name in the popup. And even then not by accident...


Have you tried recently the Info link in the same balloon, or in right-click menus? The Info pane offers table reports including reports for index space usage and fragmentation. Though reports vary by database type.
Mon May 08, 2023 8:48 am View user's profile Send private message
gemisigo



Joined: 11 Mar 2010
Posts: 2108

Post Reply with quote
SysOp wrote:
Have you tried recently the Info link in the same balloon, or in right-click menus? The Info pane offers table reports including reports for index space usage and fragmentation. Though reports vary by database type.


I've been tinkering with the DB Query powering that popup for a very long time now (you can see the recently updated version of it here), but I never noticed those links to the reports on the right side of that pane. Another fine example of literal (or rather lateral?) "tunnel vision" :) Since when are those there?
Wed May 10, 2023 2:42 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7847

Post Reply with quote
Access to the Properties dialogs via name hyperlink was introduced in 12.0, the report links in the Info panel were introduced in 12.2, not that long ago. They are also accessible via menus in the Database Explorer, with a few more clicks. You can add custom reports as well, if you save them to C:\Program Files (x86)\SQL Assistant 12\reports\[db type]\Object Info\Table folder. Their names will be added to the Info pane and to right-click menus.
Wed May 10, 2023 8:33 am View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
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


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.