|
ApexSQL Knowledgebase Tips and How-to Articles for Apex SQL Tools Using Snippets to create data-based Intellilist functionallity DESCRIPTION ApexSQL Edit has a very powerful Intellilist feature for helping you write SQL Syntax and database objects. When the intellilist information you need comes from the database itself, ApexSQL Edit's feature comes in handy. ApexSQL Edit’s snippet feature can be used to create Intellilist-values that comes from the data in your database. This feature can be taken one step further to substitute a display value for a key value especially for identity foreign keys. Most stored procedures do not used hardcoded data values and so the ability to create data-based Intellilist functionality is very useful for data mining or creating ad hoc queries. SOLUTION To illustrate, we will create a new snippet that lists Categories from the Northwind Database. Once a Category is chosen, its Category ID will be inserted to the editor. Go to Tools > Manage Snippets to open the snippet manager: ![]() Click on the “Advanced” button to launch the Custom Snippet Replacement Management Editor. ![]() Custom Replacements can be thought of as custom list-based variables to be used in Snippets. This solution will define one that will show a list based on a result queried from the database. Select the New button from the bottom right of the Custom Snippet Replacement Management window to add a new replacement. Create a new Replacement filling in the values as shown below: ![]() For the Replacement Type select “DataList” (“List” is used to hard code your list values). ![]() Fill in the “DataList Query” with the following text: ![]() The values returned in the "as display" column will be displayed in the drop down list.The values returned in the "as value" column will be substituted for the display value when it is selected.(If you do not want any substitution, select only one column.) Leave Values List empty. (Note: To hard code a list of values you would enter them there.This is used in conjunction with List as a Replacement Type.) Select “OK” to close the Custom Snippet Replacement Management window and return focus to the Snippet Manager. Now that the Custom Replacement is made, we need a snippet that will hold it. To do this, right click on the Snippet folder and select “Add Snippet”. ![]() Enter the name you want to save your snippet as in the Create New Snippet save dialog.After you save the new snippet, enter a Description, Shortcut and Title in the Snippet Manager datagrid. ![]() Click on ellipse button next to Snippet Literal Replacments to lauch the Snippet Literal Colelction Editor.(The ellipse button is not present until you click on that row.) Snippet literals can be thought of as variables for your snippets.If they are not named the same as a Custom Replacment then the user will be prompted to enter free text for the variable when the snippet is run.Click the “Add” button to create a new literal and set the Literal ID to the same value as your Custom Replacement. The last step is to add your Custom Replacement/Snippet Literal to the Snippet text.In the editor below the data grid, add the text “$CategoryID$” (without the quotes). You can add more Custom Replacements, Literals, and static text to construct a large snippet. For this example, we will simply use the custom replacement. Note that surrounding a word with the $ tells ApexSQL Edit that the word is a literal. Select the "Save and Close" button to close the snippet manager. Back in the main edit window, at the end of a line, type in your snippet shortcut followed by a tab (the shortcut invocation of a snippet only functions if there is no text after it). A drop down will appear showing all the display values from the custom replacement query. (Ctrl+Alt+S or Right Click->Insert Snippet can also be used to select a snippet if you forget the shortcut.) ![]() After a display item is selected from the list, the corresponding Value Item is entered in the query. ![]() SEE ALSO ApexSQL Edit Snippets LAST REVIEW 28 August 2007 Labels: Apex SQL Edit |
© 2008 Apex SQL Tools All Rights Reserved | 1.919.968.8444 | Contact Us | Terms of Use









