0
votes

I've been trying to get my AHK-Script running in SSMS2017 to execute a single (multi-line) SQL Statement (similar to Ctrl+Enter in SQL Developer).

The idea is that I search for the last (with respect to the last caret position) ";" in my code and highlight the text until the next one and then execute it with F5.

So far my script looks like that:

^ENTER::

CoordMode, Caret, Screen
CoordMode, Mouse, Screen

send ^f

sendraw `;

send {Enter}

send {Esc}

send +{F3}

send {Right}

X1 = A_CaretX
Y1 = A_CaretY

send {F3}

send {Right}

X2 = A_CaretX
Y2 = A_CaretY

MouseClickDrag, Left, X1,Y1,X2,Y2, 100

send {F5}

return

which in my opinion at least syntactically should work. But it doesn't. Apparently because A_CaretX and A_CaretY seem to be empty (I've let AHK output them to me and they are blank). Does anyone know a solution to this problem?

1

1 Answers

0
votes

A_CaretX and A_CaretY doesn't work in SQL Server Management Studio because the Query window is not a normal Textbox control, and so you will never be able to get the information using the Carets.

A different way to do it is to copy all the text from the query window, parse it, and loop through the parsed info, pasting and running each parsed text.

^ENTER::
Send ^a
Send ^c
ClipWait 1 ; Wait for clipboard to be filled

Queries := ClipBoard

Loop, parse, Queries, ";"
{
  Send ^a
  Clipboard := A_LoopField
  Send ^v

  Sleep 100
  Send {F5}

  Sleep 1000 ; wait 1 second for query to finish
}

;Replace the text with the original text
Clipboard := Queries
Send ^a
Send ^v

Return