# TextExpander and SQL

**URL:** <https://community.textexpander.com/t/textexpander-and-sql/190>\
**Category:** TextExpander Talk\
**Tags:** productivity\
**Created:** [May 1, 2025, 6:27pm UTC](https://community.textexpander.com/t/textexpander-and-sql/190 "2025-05-01T18:27:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![roger](https://sea3.discourse-cdn.com/textexpander/user_avatar/community.textexpander.com/roger/32/1_2.png) [@roger](https://community.textexpander.com/u/roger)\
**Post date:** [May 1, 2025, 6:27pm UTC](https://community.textexpander.com/t/textexpander-and-sql/190/1 "2025-05-01T18:27:22Z")

</div>

I’m not sure about everyone else, but whenever I need to run a database query, I can never seem to remember the exact SQL syntax. To make things easier, I’ve started saving my queries as TextExpander snippets, and it’s been a game-changer. Here are a few of the ones I use regularly—hopefully they’ll be helpful to others as well:

abbr: _ **;sqldate** _

```auto
date_field >= DATEADD(Day ,-30, current_date)
date_field >= '1/1/2025'

```

abbr: _ **;sqlcast** _  
`CAST(date_field AS DATE) as date`

abbr: _ **;sqlqual** _

```auto
select row_number() over(partition by KEY order by FIELD asc) as rn
from database_name
qualify rn = 1

```

abbr _ **;sqlarray** _  
`where field in (1,2,3)`

abbr _ **;sqlstring** _  
`CHARINDEX('string', Column1) > 0`

abbr: _ **;sqlcreate** _  
`create or replace view table_name as ()`

Anyone else have cool sql snippets?

---

<div class="post-metadata">

**Author:** ![jeffo](https://sea3.discourse-cdn.com/textexpander/user_avatar/community.textexpander.com/jeffo/32/61_2.png) [@jeffo](https://community.textexpander.com/u/jeffo)\
**Post date:** [May 1, 2025, 10:42pm UTC](https://community.textexpander.com/t/textexpander-and-sql/190/2 "2025-05-01T22:42:04Z")

</div>

@roger Love the use cases here for using TextExpander to help with repetitive SQL commands and queries. When I joined TextExpander and discovered this use case in my role as the data analyst, it too improved my SQL productivity. Here are a few of my saved Snippets:

abbr ;sqlepoc (inserts the command on how to change dates stored in EPOC format to calendar format)  
`dateadd('ms', <epoc column name> ,'1970-01-01')`

abbr ;sqlgrant  
`grant <database privilege> on <db object> in <schema name> to role <role name>;`  
This has been a time saver not having to search google for the syntax. At the same time, I can create drop down lists or user fill-ins to enter the elements within the \<\>.

Along with the personal SQL snippets, we created Shared Team SQL snippets to support our finance and customer facing teams. Creating SQL report snippet that our teams can expand allows them to self-serve on specific requests without the involvement of the data or engineering teams. These generally start as a one-off request and when the usage meets a threshold, they become candidates for a formal dashboard or report in our BI tools.

Looking back on my data analyst career, I wish I had found TextExpander sooner. The number of hours I could have saved in sharing and expanding existing SQL snippets vs having to dig through GitHub repositories, looking through old code or asking co-workers to copy/paste and share their code would have been immeasurable.

---

<div class="post-metadata">

**Author:** ![RyanSodziak](https://sea3.discourse-cdn.com/textexpander/user_avatar/community.textexpander.com/ryansodziak/32/208_2.png) [@RyanSodziak](https://community.textexpander.com/u/RyanSodziak)\
**Post date:** [May 5, 2025, 5:48am UTC](https://community.textexpander.com/t/textexpander-and-sql/190/3 "2025-05-05T05:48:59Z")

</div>

This is a great idea. I used some of them to create my own. I then started to insert pop up menus and values for the common variables that I use. Such as the Dateadd. Used a menu to display all the valid increments that can be used such as Day, Hour, Month etc.

This is a wicked time saver.

---

<div class="post-metadata">

**Author:** ![roger](https://sea3.discourse-cdn.com/textexpander/user_avatar/community.textexpander.com/roger/32/1_2.png) [@roger](https://community.textexpander.com/u/roger)\
**Post date:** [May 5, 2025, 6:28pm UTC](https://community.textexpander.com/t/textexpander-and-sql/190/4 "2025-05-05T18:28:01Z")

</div>

Love the extra popup menu variables - that is a great idea. I will add that to my snippets.
