Toad World® Forums

Execute current statement where the cursor is


#1

I want to execute only the one sql statement where the cursor currently resides. The only way I found is to highlight the statement and press F5 or F9. My searching for help has brought me to this page:
http://toadformysql.com/thread.jspa?threadID=35348
However, the behaviour of F9 seems to have changed since then, as the help even states: “Execute all statements as a batch”.
I tried many keys, terminated all sql statements with a semicolon, have an empty newline between them, but cannot get Toad to work that way without highlighting. What am I missing?
I’m using the freeware version of Toad for SQL Server 5.8.0.831.


#2

Hello SanskritFritz,

Can you send more info about what are your statements you want to execute? Now F9 executes all statements that constitute a batch.

regards, Julia.


#3

Hi there, it is very simple. I have a file where I collected several sql select and update statements which I use on a daily basis working with a database. I know about Toad snippets, but I have to use that file in another client program as well, and have to share it with my colleagues who don’t use Toad.
So my file looks like this:

select * from table1;

select * from table2;

update table1 set field1=:myvar where pk_table1_id=:myid


#4

Actually I still don’t see the problem.
I was able to execute statements from your post on my side.

Julia.
update table1.png


#5

I looked on your post again and if you want to execute only one statement (select * from table1) you can only highlight this statement and press F5. There no special button to execute separate statement.

Is it what did you ask?

Julia.


#6

Yes, this is what I asked.
My question is, why was this very useful feature deprecated? It is rather tedious to highlight a 32 lines long sql select everytime I want to execute it. Or imagine this update statement consisting of 2 lines:
update table1 set field1=‘some text’
where table1_id=:myid
If I acciedentally highlighted only the first line, I would update the whole table.
It would be much easier to just put the cursor somewhere in the statement and press a dedicated key to execute only that one select or update for that matter. I worked years earlier perfectly.


#7

You can use GO separators to organize your script by batches. So F9 will work fro you as Execute current statement from a batch. To execute several batches you can use also Script Map. It supports to execute multi-batches.
Actually I’m not sure it worked earlier in another way.

Julia.


#8

Thanks for those useful ideas.

I am quite convinced it worked before, but I’m talking about 15 years ago when I was using Toad for Oracle (actually TOAD was only for Oracle in the beginning, it was first freeware-only and then many users pursuaded the original author to split Toad into a free and shareware version, so he joined Quest for this reason. Wow, I’m old!).


#9

I believe it is Toad for Oracle only feature b/c of Oracle specific.


#10

I understand. However recognising empty lines or semicolons in a file is definitely not Oracle specific. Can you consider this as a feature request then?

I would like to execute a part of a file where the cursor is, in the following way: Toad should consider the lines above and under the cursor (including) as one statement until it finds an empty line. Alternatively parsing semicolons at the end of a line would have t he same result.

Where do I put up officially a change request?


#11

We already created change request for this. Waiting to discuss it with team.
thanks for the post.


#12

Ah, great, thank you.


#13

Just so you know - we will try to implement this in the Future releases (CR107807)


#14

That is good to hear. Is there a public way to watch a ticket like this?


#15

Unfortunately not. The reason why we post ticket numbers here is just for reference and so we can easily find it in bug tracking system…


#16

Of course, neither empty line nor semicolon is Oracle-specific :). The only problem is both also are not mandatory for SQL Server. But we’ll see if parser can help us here.

At the same time, if you have to insert emty line between statements, why not to insert line with GO word (or whatever batch separator you defined) instead? Just an idea.

Thanks,

Igor.


#17

Yes, this is what I’m doing right now, as already suggested be Julia here: http://toadforsqlserver.com/message.jspa?messageID=141361#141361
Thanks again!


#18

I would like to add my vote to implement a separate execute-current-statement function that obeys semicolons, in addition to the existing one that obeys GO. This was a chief distinguishing benefit of using Toad for MySQL, and now that my organization has “upgraded” to SQL Server we are having a tough time finding an query editor that has this functionality (SQL Complete’s version is not reliable).

  • KJ

#19

Glad to let you know this feature in now implemented. Now F9 executes only current statement even if there are no delimiters at all, e.g. if you write “select 1 select 2 select 3” and press F9 while caret is within second select, you’ll get “2” in the results window.
Thanks for your participation in our beta! Enjoy!


#20

Thank you, that is great news indeed! I would encourage you to separate the functionality out so that users can choose different keystrokes to activate them, i.e. one keystroke each to execute-current-statement respecting:

  • Line breaks
  • Semi-colons
  • Go

This may seem like too much flexibility, but in fact I think if used intelligently can be a big productivity booster.

Also, I assume calling execute-current-statement will limit the execute to a highlighted section?

I look forward to the next beta drop. Any chance this can be made as a non-beta 5.8.2 improvement as well?

Best,
KJ