0

In a SQL Stored Procedure, I'm working on some code that has a lot of nested Case Statements that are tough to decipher where they start and end. I was wondering if anyone knows of a keyboard shortcut similar to Ctrl+] for Parenthesis that will take you to the End part of the Case statement if you have the Case keyword highlighted or something similar? I'm open to other possible suggestions as to how to simplify this as well.

Tim F
  • 119
  • 1
  • 8
  • Not aware of such a shortcut, but you may want to investigate using `CROSS APPLY (VALUES` to compute new columns and reuse them later, see https://stackoverflow.com/questions/65818438/possible-to-store-value-of-one-select-column-and-use-it-for-the-next-one/65818648#65818648 and https://stackoverflow.com/questions/66275139/how-to-apply-case-when-result-to-the-where-condition-in-sql-2008-query/66275625#66275625 – Charlieface Aug 04 '21 at 13:40
  • SSMS does automatically highlight the corresponding `CASE` when you select the `END` of a case expression, and vice versa, but I am not aware of anything that will navigate for you. Once solution would be to simply do a find and replace to replace `CASE` with `(CASE` and `END` with `END)` and just use the `Ctrl + ]` on parenthesis – GarethD Aug 04 '21 at 13:51
  • @GarethD I just tried again to click on CASE/END and highlight them and I don't see any highlighting of the corresponding CASE/END. This is on SSMS 2018, although I am a few versions behind so maybe that's the issue. Is it an option you may have turned on? With that said, the idea of replacing with the parenthesis is very clever and works. If anyone else is thinking of using this just be careful of replacing the END used for IF statements or the END of the Stored Procedure. Thanks! – Tim F Aug 04 '21 at 13:59
  • The highlighting on mine is quite faint, but definitely visible. [Screenshot here](https://i.stack.imgur.com/HKb58.png). I don't recall turning it on, but thinking about it though, that could well be something that SQL Prompt is doing rather than something SSMS does as standard – GarethD Aug 04 '21 at 14:15

0 Answers0