Macro to change the case of SQL keywords.

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
ravilobo
Posts: 18
Joined: Fri Dec 14, 2007 8:45 pm

Macro to change the case of SQL keywords.

Post by ravilobo »

Does any one have a macro to change the SQL keywords to UPPER case?
ben_josephs
Posts: 2459
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

You can do this wih a single regular expression search and replace:
Find what: \<(select|insert|update|from|where|and|order by|left|right|outer|inner|join|...)\>
Replace with: \U\1

[X] Regular expression

Replace All
You can get a complete list fom the documentation for your brand of SQL server.

This assumes you are using Posix regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
ravilobo
Posts: 18
Joined: Fri Dec 14, 2007 8:45 pm

Post by ravilobo »

Thank you Ben!

While the solution works for most of the times, I have following scenarios

1. what if I have a variable like lv_select

to solve the above problem i I prefix and suffix a space in the FIND WHAT then,

1. what if the keyword is the first or last word in the line ?

One more question,

what is Posix?
ben_josephs
Posts: 2459
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Try it. The regular expression I suggested doesn't match lv_select. That's what the \< and \> are for. \< makes the regular expression match a string only if it begins at the beginning of a word; \> makes it match a string only if it ends at the end of a word. Look in TextPad's help under Reference Information | Regular Expressions.

In this context Posix is just a syntax for regular expressions. It differs from TextPad's default in whether the characters (, ), {, } and | are preceded with a backslash to make them literal (Posix) or to make them special (default). See TextPad's help under How to... | Find and Replace Text | Use Regular Expressions.
ravilobo
Posts: 18
Joined: Fri Dec 14, 2007 8:45 pm

Post by ravilobo »

Thank you Ben!

It worked perfectly well. THANK YOU for taking time to explain the whole thing in detail.

Please forgive the ignorance of a novice. Thank you again.
User avatar
talleyrand
Posts: 625
Joined: Mon Jul 21, 2003 6:56 pm
Location: Kansas City, MO, USA
Contact:

Post by talleyrand »

Tip of the hat to Ben as well for this. One of my current tasks is to get this new TSQL code base into a consistent format and while heavy use of ctrl-U has been handy,
\<(select|insert|update|from|where|and|order by|left|right|outer|inner|join|as|with|if|begin|end|or|between|exists|in|cross|all|any|like|not|null|create|drop|prodcedure|function|table|trigger|view|alter|exec|execute|add|asc|desc|delete|return|cursor|declare|into|is|set|output|rank|grant|union|use|values|case|when|top)\>
is far more efficient.

That is a S&R that is getting dropped into my clib book of handy things.
I choose to fight with a sack of angry cats.
Post Reply