Settings and activity

  1. 16 votes

    We're glad you're here

    Please sign in to leave feedback

    Signed in as (Sign out)

    We’ll send you updates on this idea

    3 comments  ·  SQL Prompt » Format SQL  ·  Flag idea as inappropriate…  ·  Admin →
    Mathieu Proulx supported this idea  · 
    An error occurred while saving the comment
    Mathieu Proulx commented  · 

    Yes! It would be really great if we could convert a normal SQL into a dynamic SQL to pass different variables in parameters.

    SELECT p.Id FROM MyStore..Product AS p
    LEFT JOIN OtherDatabase..Specs AS s on s.Id = p.Id
    p.Deleted = 0 AND
    s.Color = 'Blue'

    Once selected and converted using the new SQL Prompt shortcut, would become :
    SELECT @SQL = N'SELECT p.Id FROM MyStore..Product AS p' +
    N'LEFT JOIN OtherDatabase..Specs AS s on s.Id = p.Id' +
    N'WHERE ' +
    N'p.Deleted = 0 AND' +
    N's.Color = ''Blue'' '

    while converting single quote in double quotes '' and while keeping the code alignment provided by the "Format SQL" command.

    I know it would be a HUGE asset and would save a lot of people lots of time formatting it by hand, since this is the only way of passing a Database name by parameter to a Stored Procedure in T-SQL.