How do I analyse a string length and punctuation with SQL?

Need a quick re-cap of some of the text functions in SQL? By using a combination of them, you can:  count the number of words in a string find if a string starts with a number find if a string contains a particular punctuation sign find if a string ends in a particular punctuation sign … Continue reading How do I analyse a string length and punctuation with SQL?

How do I find the first position of a string within a string with SQL?

Depending on the database you're using, the function will be called differently and may have different syntax. MySQL, vertica instr(full string, string to search) PosgreSQL position(string to search in full string) SQL Server charindex(string to search, full string, {starting position}) As you might have noticed, the function in SQL Server has an additional argument, allowing … Continue reading How do I find the first position of a string within a string with SQL?

How do I find the difference between two time periods?

Apart from the standard datediff() and timestampdiff(), Vertica and MySQL offer a couple of more ways to go about it: By using the age functions:  age_in_years (current date, start date) and  age_in_months (current date, start date)  A key thing to remember about these two is that, unlike  datediff ('years', start date, current date), they will calculate the months/years between the … Continue reading How do I find the difference between two time periods?

How do I find the next Monday/Tuesday/etc.. with SQL?

Being able to calculate the date of the coming Thursday may come really handy if your sales revenue follows a very strong weekday pattern as it enables you to use weekdays, rather than fixed dates, as a basis for making your weekly financial projections. How do I do this in practice? Vertica offers a very … Continue reading How do I find the next Monday/Tuesday/etc.. with SQL?

How do I find the last day of the previous/next month with SQL?

Need to provide a daily estimation of how many clicks you'll make by the end of next month? Your client expects you to deliver a monthly report on their performance? That's when knowing how to get the last day of the current, previous or next month might come in handy Whereas Vertica and MySQL offer … Continue reading How do I find the last day of the previous/next month with SQL?