SQL Server function for getting values from JSON

Recently, I needed to build a report based on data in a SQL Server table that had as one of its fields some JSON data. The report was going into Excel, and initially, I was just parsing the JSON and putting in every key/value pair into the spreadsheet. (I did all that in C#.) I found that the client only wanted a few discrete fields from the JSON, so I instead wrote this SQL Server function that will get the value based on the input JSON "field":

USE utility;
SET ANSI_NULLS ON;
SET QUOTED_IDENTIFIER ON;

IF OBJECT_ID('dbo.GetJSONValue') IS NOT NULL
  EXEC ('drop FUNCTION dbo.GetJSONValue;')
GO


CREATE FUNCTION dbo.GetJSONValue(
    @json varchar(max),
    @fieldName varchar(255)) RETURNS varchar(255) AS
BEGIN
    declare @fieldStart int;
    declare @startIndex int;
    declare @nextValueIndex int;
    declare @length int;
    declare @value varchar(255);
    declare @valueReversed varchar(255);

    set @fieldStart = charindex(@fieldName, @json);

    if @fieldStart <= data-preserve-html-node="true" 0
    begin
        set @value = null;
    end;
    else
    begin
        set @startIndex = charindex(@fieldName, @json)+len(@fieldName)+2;
        set @nextValueIndex = charindex(':', @json, @startIndex);
        set @valueReversed = reverse(substring(@json, @startIndex, @nextValueIndex - @startIndex));
        set @length = len(@valueReversed) - charindex(',', @valueReversed);
        set @value = replace(substring(@json, @startIndex, @length),'"','');
    end;

    return @value;
end;
GO

grant execute on getjsonvalue to public;

VirtualBox Windows guests to run IE on Mac

When I left my "corporate job" (in order to start my own corporation), I also left behind (if only temporarily) Windows in favor of my trusty MacBook (and my even trustier Mac Mini server). But of course, I still need to test on Windows from time to time, and so I've been using VirtualBox with some Windows guests. The best way to wrangle that is from this 2011 article: Internet Explorer for Mac the Easy Way: Run IE 7, IE8, & IE9 Free in a Virtual Machine.

Fabulous site for SQL Server help

Some search I did recently for help on a SQL Server topic led me to http://www.brentozar.com, which I have found to be an extremely useful site.  Although I've worked with SQL Server for a number of years, I am much more proficient (and comfortable) with Oracle.  (Now that I'm older and wiser, I won't get into which is better...  there's room for all RDBMSes in this world.)  But one of the things I like most about the Brent Ozar site is how high-level it is:  they delve deeper into issues and provide a lot of good evidence for their assertions.  It's also nice that they share their knowledge (and scripts) for free.  And they have a good sense of humor.