Category: T-SQL

  • CASE WHEN “I need to learn more T-SQL” THEN GoogleTheResult() END

    One of my favorite recent discoveries in my SQL Server work recently, is the awesome T-SQL “CASE…WHEN…THEN” statement. I can’t describe how much I love this thing. It’s pretty simple really: SELECT CASE WHEN fruit = ‘apples’ THEN ‘not oranges’ WHEN fruit = ‘oranges’ THEN ‘not apples’ ELSE ‘neither apples nor oranges’ END AS fruit…

  • Backing up all SQL Server user databases to file

    The ultimate lazy backup script. I wasn’t feeling to selective about which databases to backup, and I figured, it’d be best to back them all up, even that testing database I occasionally use for data import/export. Never know when I might need it again… This sits inside a SQL Server Agent job, and runs nightly. Simple enough…