How to create a snippet that uses table metadata?

rgelbrgelb Posts: 46 Bronze 4
edited October 30, 2024 9:17PM in SQL Prompt
I would like to write the following sql via a snippet: 

SELECT TOP 10 * 
FROM dbo.Documents d 
ORDER BY 1 DESC 

So to do this, I have a snippet: 

SELECT TOP 10 * 
FROM $CURSOR$ 
ORDER BY 1 DESC

However, I want to take it a step further. I want to replace ORDER BY 1 DESC with ORDER BY {PRIMARY_KEY}. And the primary key should be selected based on the table that I entered at the $CURSOR$ placeholder. 

So the result after I tab out of the $CURSOR$ should be:

SELECT TOP 10 * 
FROM dbo.Documents d 
ORDER BY ID_Document DESC 

Is that possible?

Answers

  • Hi @rgelb

     

    Thank you for reaching out on the Redgate forum regarding your SQL Prompt snippet question.

     

    Having a look into this, and it is not functionality that currently exists.

    Snippets currently have options to use placeholders or template parameters, which can provide some static versatility for snippets. 

    There isn't a process to actively query metadata from a placeholder that would update as it changes.

     


    I would certainly recommend logging this on our UserVoice site as a possible feature request. 

    It's a very intriguing concept that has some wide possibilities for functionality.


    UserVoice is our way for users of our products to communicate directly with our development & product teams to highlight features & functionality to be implemented into our tools.

    For SQL Prompt, the link is https://redgate.uservoice.com/forums/94413-sql-prompt

     

    Jon Kirkwood | Technical Support Engineer | Redgate Software
Sign In or Register to comment.