Author |
Message |
seth.rothman
Joined: 29 Jan 2008 Posts: 54 Country: United States |
|
Closing Intellisense after CTRL-V |
|
I'm always writing short SQL statement to grab data out of the database, only to use the results as the criteria for a new SQL statement. For example, if I write a quick SELECT * FROM Contact WHERE FirstName = 'Bob' and I need the ContactID field for a totally separate bit of SQL I'm going to write, I will copy copy the value from the results of the first statement I wrote and then start typing the next one. For example, once I had the appropriate ContactID value on the clipboard, I'd type "SELECT * FROM Note WHERE ContactID = ". The intellisense will popup after I type the "=" and then I'll paste my value there. I'd be more logical to me if the intellisense dropdown closed at that point so I could hit ENTER and then SHIFT-UP ARROW to highlight the SQL so I F5 it to run it (yes I'm using SMSS). What I've grown accustomed to doing is first hitting ESC and then going on about my business, but it's always been a bit of a nuisance.
I'm using the 5.0.67 beta, although I believe the behavior existed like this since the beginning of time. I figured if there was any hope that you agreed with me, it may make it into the final release of v5. Thx.
|
|
Thu Mar 25, 2010 11:29 am |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
There is a better way to do that using new $$...$$ macros. I believe you can automate the entire process. Please check the examples in User's Guide, search for $$...$$ or Advanced Code Snippets.
|
|
Thu Mar 25, 2010 1:34 pm |
|
 |
seth.rothman
Joined: 29 Jan 2008 Posts: 54 Country: United States |
|
|
|
I'm not familiar with the $$ macros, but the majority of the SQL I'm talking about is more of an ad-hoc nature so I wouldn't think I'd have any saved macros for it.
|
|
Fri Mar 26, 2010 8:30 am |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
1. You can program $$...$$ macro to grab the line text, execute it, paste result into the editor , all with a single key press
Let's take your sample code
SELECT * FROM Contact WHERE FirstName = 'Bob'
and re-enter it as
 |
 |
SELECT TOP 1 ContactID FROM Contact WHERE FirstName = 'Bob' |
Let' say you setup a new snipept with the code like
 |
 |
SELECT * FROM ... WHERE ... = $$ $CURRENT_LINE$ $$ |
And set Alt+0 as the hot key
Now if you enter
SELECT * FROM Contact WHERE FirstName = 'Bob'
and press Alt+0
you are going to get (let's say the returned value is 55)
 |
 |
SELECT * FROM ... WHERE ... = 55 |
This way, you get the code executed, you get the result pasted into the editor, you get a template for the next statement all with a single key press, no popups, no manual copy & paste
2. Another snippet idea ( a bit more advanced )
 |
 |
SELECT *
FROM $OBJECT$
WHERE $$ SELECT TOP 1 name FROM syscolumns WHERE id = object_id('$OBJECT$') ORDER BY colid $$ = $$ $CURRENT_LINE$ $$ |
The above should prompt you for the second table and generate the entire second statement, including complete FROM and WHERE clauses with table and column names, and the value returned from the first statement.
|
|
Fri Mar 26, 2010 9:18 am |
|
 |
seth.rothman
Joined: 29 Jan 2008 Posts: 54 Country: United States |
|
|
|
That's pretty cool stuff. I'll definitely play around with them more. I'm still curious if you think my idea on closing the popup after a paste is a good idea...
|
|
Fri Mar 26, 2010 10:17 am |
|
 |
gemisigo
Joined: 11 Mar 2010 Posts: 2165
|
|
|
|
If it counts, I vote for that too. Though it's not a big deal to press escape it can be much more convenient this way.
|
|
Fri Mar 26, 2010 1:06 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
Can somebody describe for me what exactly is "this way?"
|
|
Fri Mar 26, 2010 4:05 pm |
|
 |
gemisigo
Joined: 11 Mar 2010 Posts: 2165
|
|
|
|
 |
 |
Can somebody describe for me what exactly is "this way?" |
Sorry. To close the popup after a pasting clipboard contents. If it is easy to achieve.
|
|
Sat Mar 27, 2010 4:11 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
Thank you! I have submitted this request to the tracking system for further technical analysis.
|
|
Sat Mar 27, 2010 7:05 pm |
|
 |
|