Category Archives: Interesting SQL Patterns

Interesting SQL code and patterns

Filtering Using CHARINDEX

Most of the time when I need to query rows, I would use column name and LIKE operator. However, CHARINDEX operator can provide a quick way to check if a particular word or special character is present in the column. … Continue reading

Posted in Interesting SQL Patterns | Tagged , , , , | Comments Off on Filtering Using CHARINDEX

Easy Way To Randomize Records

There are some fancy ways to create random records. Some formulas/codes generate random numbers between 0/1, some others pick every Nth record. This method is very simple and works by creating a new ID string for each record and then … Continue reading

Posted in Interesting SQL Patterns | Tagged , , | Comments Off on Easy Way To Randomize Records

Converting Character Date To Datetime

I run into an interesting conversion situation when a vendor returned some birthdate data in a text format and I needed to convert it to Datetime to insert the records into the data warehouse. The obvious Cast and Convert did … Continue reading

Posted in Interesting SQL Patterns | Tagged , , | Comments Off on Converting Character Date To Datetime

Getting Data Left or Right of a Delimiter

It is a very common case when one needs to remove values left or right of a delimiter.The pattern below should work for most of the common cases. Note that JSON was misinterpreting some special characters, therefore, I posted a … Continue reading

Posted in Interesting SQL Patterns, Uncategorized | Tagged , , , , , | Comments Off on Getting Data Left or Right of a Delimiter