6

SSMS is suddenly re-formatting my stored procedure - it has never done this before. Here's an example of what I'm talking about. Here's the start of the stored procedure I created last week:

CREATE PROCEDURE [dbo].[usp_LoanDataNames]
(  
@LoanID varchar(max) = null,
@Columns varchar(max) = null,
@DataNames NVARCHAR(MAX) = '',
@SQL NVARCHAR(MAX) = ''
)
AS

All the stored procedures I created before today still have that format. But when I create a new stored procedure today, with the same exact format as above, and then pull up the stored procedure script, it looks like this:

CREATE PROCEDURE [dbo].[usp_LoanDataNames2]
@LoanID VARCHAR (MAX)=NULL, @Columns VARCHAR (MAX)=NULL, @DataNames NVARCHAR (MAX)='', @SQL NVARCHAR (MAX)=''
AS

This is a different format than before. It moved all the parameters up to immediately follow the stored procedure name, and put them all on the same line. Also (and I didn't bother posting the entire stored procedure so I didn't post this part), it changes Exec to Execute. And it changes the indenting on various lines, and changes many lowercase words to uppercase.

It even will change the formatting if I do it this way:

CREATE PROCEDURE  [dbo].[usp_LoanDataNames] 
AS

DECLARE 
@LoanID varchar(max) = null,
@Columns varchar(max) = null,
@DataNames NVARCHAR(MAX) = '',
@SQL NVARCHAR(MAX) = ''
 )

It will change that to:

CREATE PROCEDURE [dbo].[usp_LoanDataNames2]
@LoanID VARCHAR (MAX)=NULL, @Columns VARCHAR (MAX)=NULL, @DataNames NVARCHAR (MAX)='', @SQL NVARCHAR (MAX)=''
AS

Any idea why this is happening? We have certain standards we use here, and the original stored procedure is formatting my company prefers. The problem is I CAN'T use that formatting anymore, because every single stored procedure I create or alter automatically re-formats now. Any ideas?

Thank you.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
M74d3
  • 61
  • 4
  • 1
    Any updates to your SSMS or Sql Server that this might relate to? – Stefan H Jan 02 '18 at 19:59
  • Hi Stefan - not that I know of. We updated SQL Server 2014 to 2016 about 3 weeks ago, and I updated SQL Server Management Studio from a previous version (I forget what it was) to v17.4 about two weeks ago. But nothing that I'm aware of since then. And this just started happening today, so it doesn't seem related to that. I tried searching online for an answer to this, assuming that this would be a common issue and that I'd find an answer almost immediately, but to my surprise I can't find anything about this anywhere. – M74d3 Jan 02 '18 at 21:11
  • 1
    Are you using any add-ins to SSMS? Maybe one of them updated and has new behaviour? – DancingFool Jan 03 '18 at 07:30
  • If I am using add-ins, it certainly isn't intentional. I never downloaded any add-ins. Is there some way to pull up a list of all add-ins being used by SSMS (if any). I'm going through the drop-down lists and looking for add-ins, but no luck yet. – M74d3 Jan 03 '18 at 17:55
  • I had previously been using SQL Server Management Studio (SSMS) 2016 with no issues. 3 weeks ago I downloaded SSMS v17.4, and have been using it since then with no issues Suddenly, this reformatting issue started happening yesterday. I still have no idea why. But I still have SSMS 2016 on my computer. So I just opened the 2016 version and created a few test stored procedures, and it works just fine. No re-formatting issues. So at least I have a workaround. That still leaves me with the problem of having no idea why v 17.4 suddenly started re-formatting, or how to fix it. – M74d3 Jan 03 '18 at 18:07
  • So at least I have a workaround. But I'd still rather use v17.4, so I'm still trying to figure out how to get v17.4 to stop this re-formatting nonsense. – M74d3 Jan 03 '18 at 18:12

1 Answers1

10

This happens when you are working with Always Encrypted and have the option "Enable Parameterization for Alway Encrypted" enabled.

To fix:

  1. Go to: Query > Query Options > Execution > Advanced
  2. un-check Enable Parameterization for Alway Encrypted (its at the end of the list)

You should only have this option enabled when you are working with ad-hoc queries and not stored procedures.

Ashley Medway
  • 7,151
  • 7
  • 49
  • 71
  • 1
    Thanks a lot, that's definitely it. I appreciate the response! – M74d3 Jan 18 '18 at 01:59
  • Thanks. I see that the setting goes back to checked after executing alter procedure. – Gregory Bologna Nov 12 '20 at 19:56
  • This answer is correct. If you want to have this turned on for only a certain query window, select Query from the main menu, select Query Options, go to Execution > Advanced, select "Enable Parameterization for Always Encrypted". https://learn.microsoft.com/en-us/sql/relational-databases/security/encryption/always-encrypted-query-columns-ssms?view=sql-server-ver16#enabling-and-disabling-parameterization-for-always-encrypted – Gen1-1 Jul 19 '22 at 12:44