Inserting Records Conditionally
I faced a typical problem at work not too long ago dealing with inserting conditional data into a table. Typically I would write a bit of code to handle the conditional logic, but I thought about the problem for a bit and came up with a different solution using SQL. Here is the background of…
Hierarchical Data in SQL Server
Often times in applications, I am required to maintain data that has a hierarchical relationship such as a tree structure. The easiest way to approach this problem is to add a key to the table that refers to the record’s parent key. For example, in my last project, I needed to have a table that…
RiverMate – An Android App for River Levels
This free android app gives you the latest river level oberservations for rivers all over the United States. By selecting your state and/or county, you can select the rivers that you want to monitor. Add as many river gauges as you wish and they will be displayed and updated in real time on the app's…
Using SQL to get the number of occurrences of a character in a string in SQL Server
This SQL Snippet can be used to get the count of a single character, or an entire phrase, in a string. We have a seperate post for doing the same thing in Oracle. Assume you have the string “a,b,c,d,e” and you want the count of commas (“,”) contained in that string. Just use the SQL below:…