 |
SoftTree Technologies
Technical Support Forums
|
|
Author |
Message |
salmarko
Joined: 04 Apr 2012 Posts: 1 Country: Serbia |
|
Generating DECLARE statement |
|
Hi. Is there a way to insert DECLARE keyword based on selected parametar in query. Example:
SELECT OrderId
FROM Orders
WHERE CustomerId = @CustomerId
I would like to select @CustomerId param, and then to press some global key combination, and assistent should insert "DECLARE @CustomerId INT" above this query. Is there a way to do this? If not, maybe it would be a good feature?
|
|
Wed Apr 04, 2012 3:55 am |
|
 |
gemisigo
Joined: 11 Mar 2010 Posts: 2165
|
|
|
|
A similar (yet not exactly identical) effect could be achieved using snippets, regular expressions and selecting the whole query. You'd have to select all of it because you cannot retrieve the type of the variable otherwise. But by selecting everything you cannot decide which variable to declare so it would declare them all.
Adding variables to the script before declaring them and then going back to declare them when developing a code is a bit awkward (though I must admit it happens) and designing database doing this regularly is somewhat... clumsy... It shows the lack of forethought.
A snippet that could do this would be extremely complex. For example, to avoid re-declaration of already declared variables, the whole contents of the editor should be selected and parsed for a rather large number of different cases. Creating and using this snippet would be cumbersome to the extent I consider "not worth the effort by far".
I can imagine it as some kind of refactoring function, though. These appear to have more control over the contents of the editor. But they are an unknown area for me. While the existing refactoring queries can be modifed I doubt there are user defined refactorings. Now those would be a mean feature to add :)
|
|
Wed Apr 04, 2012 4:57 am |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|