|
I have a "memBaseSQL" field where I want to script out the parentheses from SELECT TOP (100) PERCENT statements.
(comments are locked)
|
|
I think this is what you want:
(comments are locked)
|
|
I would use a regular expression CLR to do that - if you just replace brackets it will affect the whole statement, and could easily change the meaning of arithmetic expressions (for example - select ((1 + 2) * 3) = 9, whereas SELECT 1 + 2 * 3 = 7) or logical constructs. If you were to use a regular expression
And use the replacement expression
Then you will end up with the brackets removed just in that part of the statement. Matt, I'm not sure why you would want to go to the CLR and regex just to remove parentheses in this scenario when REPLACE or STUFF will work just fine.
Oct 12 '09 at 11:04 PM
Jack Corbett
Jack, pretty much for the reason I said above - REPLACE will replace all instances, not just the ones around the SELECT TOP (100) PERCENT. So SELECT TOP (100) PERCENT ((a + b) * c) FROM table would be an example where it wouldn't be sufficient.
Oct 13 '09 at 04:53 AM
Matt Whitfield ♦♦
(comments are locked)
|
|
Why use TOP (100) PERCENT at all? It achieves nothing useful and probably only indicates that the author of the code didn't know what they were doing and was relying on the "Query Designer" feature to write queries. not saying that this is the case here, but using
Oct 13 '09 at 11:20 AM
Kev Riley ♦♦
Views cannot be ordered so adding an ORDER BY clause with the 100 PERCENT clause achieves nothing.
Oct 13 '09 at 06:08 PM
David 1
(comments are locked)
|
|
The objective is to replace the top operator that has parenthesis around the numerical value. With that said the best and easiest solution is to search for this exact scenario. There are only two real scenarios that you have to check for, top with a space and top without a space. The end result is a very simple replace function.
Here is another version that allows the use of multiple percentages. What happens if it's not 100, or there are two or three spaces?
Oct 12 '09 at 07:51 PM
Matt Whitfield ♦♦
Then it does not get replaced. The requirement is to replace top (100). If other values need to be replaced I would consider running the same UPDATE with a differnt threshold. I would hope this is a one time UPDATE.
Oct 13 '09 at 10:50 PM
Adam Haines
(comments are locked)
|

