Category: TSQL

Utility function: dbo.JobName(@job_id)

As often as I have to pull a job’s name based on its job_id in the MSDB system tables, I’m truly stunned that I’ve never done this before: CREATE FUNCTION dbo.JobName ( @job_id UNIQUEIDENTIFIER ) /* A little utility function to return a job name based on the job_id. No warranty or guarantee implied. Use at […]

Fun with Operator Precedence

Let’s have some fun with operator precedence today. Specifically, logical operator precedence. Specifically, how is it evaluated when your where clause says “WHERE This AND That OR Something AND that”, without any clarifying parenthesis? Let’s play around with this. The simplest test scenario is a SELECT 1. If I get a 1 back, that means my WHERE clause evaluated […]

“Thing IS NOT NULL” isn’t the same as “Thing != NULL”

I’ve talked about NULLs before. (Ref: Here’s a bit on ISNULL(), and here’s one about understanding NULL at a basic level.)  And yet, it’s worthwhile to bring these things up from time to time. “[Thing] != NULL” is nonsense. It won’t work the way you want it to work, because NULL literally means “unknown”. Nothing in the […]