16 votesMathieu Proulx supported this idea ·
An error occurred while saving the commentMathieu 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 :
DECLARE @SQL NVARCHAR(MAX)
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.