2

In TOAD, you have keyboard shortcuts where you can select the current block or execute the current block....so if you are working on a large sql query, when you make a modification, you can just do a CTRL+ENTER (or something like that, can't recall right now) rather than having to manually highlight the block of sql and htting F5.

I'm pretty sure this doesn't exist natively in SSMS, anyone know if functionality like this exists in any Add-ins?

Sorry....some clarification....I'm talking about working in the query window, which may contain:

select * from SomeTable

select * from SomeTable
WHERE
    column1 = 'abc'
AND column2 = 'def'  <--- LET'S SAY MY CURSOR IS SITTING HERE
AND column3 = 'ghi'

select * from AnotherTable
WHERE
    column1 = 'abc'
AND column2 = 'def'
AND column3 = 'ghi'

So, I just want to execute the statement that my cursor is within.

Reg Edit
  • 6,719
  • 1
  • 35
  • 46
tbone
  • 5,715
  • 20
  • 87
  • 134

6 Answers6

2

The add-in SQL Complete has this exact feature. Execute current statement without selecting it. Their free express version has it, but I also recommend standard version for its additional features. It's a major time-saver.

Gabe
  • 5,113
  • 11
  • 55
  • 88
  • Wow, thanks Gabe! When I looked at your link it showed them choosing from a context sensitive menu (ugh!) but googling I found several pages indicating there was also a hotkey for execution as well. – tbone Sep 17 '11 at 04:36
  • Glad you found this answer helpful 4 months later. Ctrl+Shift+E is the hotkey for those who are wondering. – Gabe Sep 17 '11 at 06:33
1

You can check out this add-in for SSMS 2012. Place the cursor within the statement you want to execute and press CTRL+SHIFT+E

SSMS Executor - http://ssmsexecutor.codeplex.com/

Stanislav Stoyanov
  • 2,082
  • 2
  • 20
  • 22
1

OK, so to clarify what you're looking for... If you had the following T-SQL with text selection cursor as indicated:

DECLARE @Test Int
SET @Test = 1

IF @Test=1
BEGIN
    SELECT TestColumn1 FROM TestTable
    SELECT AnotherTestColumn FROM AnotherTestTable

    SELECT [A Valid Column]

    FROM [A Valid Table]

    SELECT LastColumn FROM LastTable ][ <- CURSOR HERE
END

You would want a certain hotkey (eg Ctrl-F5) to execute SELECT LastColumn FROM LastTable...? Or SELECT LastColumn FROM LastTable END (which is what you would get with the blank row rule you described)? Or something else? How about the statement broken up with a line break in the middle, or the two statements bunched together?

If you really wanted to use blank rows to define "blocks", then that should be pretty easy to do as an Addin (sample/tutorial here); if, on the other hand, you expected a little more "intelligence", this could be a difficult/complex task, with SQL parsing required etc.

Tao
  • 13,457
  • 7
  • 65
  • 76
  • SSMS does already define "blocks". You can expand and collapse them. Though I'm not sure what logic that uses. – Martin Smith May 17 '11 at 10:22
  • 1
    Right, but that SQL-Server-defined concept of "blocks" does not seem to match what @tbone described in a comment to the previous answer. – Tao May 17 '11 at 10:25
  • Ya, that's basically what I'm looking for....but would really rather not have to write an add-in, although I might if I have to as this drives me nuts, so thanks for that link.... – tbone May 17 '11 at 17:32
1

Would love to see this feature added to ssms query analyzer. I'm a long-time toad user.

The closest thing I've found is to highlight the query using directional arrows and then hit f5. Toad allows you to execute a query merely by placing the cursor anywhere within the query and then hit cntl+enter. It doesn't sound like much of an efficiency save but I really miss it.

Brian
  • 11
  • 1
0

I develop SSMSBoost add-in and we have recently added Shift-F5 (Select current statement), which, followed by F5 (Execute) will execute current statement. It works in all versions of SSMS from 2008R2 till latest 18.1

Andrei Rantsevich
  • 2,879
  • 20
  • 25
0

Not certain I'm following your wording, but, do you mean:

Select text down line by line starting from the cursor SHIFT+ DOWN ARROW

Execute the selected portion of the query editor or the entire query editor if nothing is selected F5 or CTRL+E or ALT+X

Parse the selected portion of the query editor or the entire query editor if nothing is selected

CTRL+F5

MSDN SSMS keyboard shortcuts

  • No....I want to avoid the manual part of 'the selected portion of the query editor' - if my cursor is sitting in the middle of a block, I want a shortcut to either select or execute that entire block (the delimiter of a "block" is a blank row) – tbone May 16 '11 at 18:33