• Skip to main content
  • Skip to primary sidebar

DBA Diaries

Thoughts and experiences of a DBA working with SQL Server and MySQL

t-sql

How to Use SQL CASE for Conditional Logic in Your SQL Queries

May 15, 2017 by Andy Hayes Leave a Comment

SQL CASE sample data

SQL CASE provides the author of the query with the ability to perform conditional logic in their SQL queries for SELECT, INSERT, UPDATE, DELETE. It is also possible to use it with SET, IN, HAVING, ORDER BY and WHERE. It comes in two formats: simple case search case Simple SQL CASE The simple CASE expression compares an expression to a set of simple expressions to … [Read more...] about How to Use SQL CASE for Conditional Logic in Your SQL Queries

Using ISNULL in SQL Server to Replace NULL Values

May 11, 2017 by Andy Hayes Leave a Comment

SQL ISNULL example before

There are different ways to handle NULL's and I wrote about one such way in my last post. In this post, we look at SQL ISNULL() and specifically at the SQL Server version. MySQL does have this function but it behaves a little differently as it returns a boolean value. Let's look at the syntax ISNULL(check_expression, replacement_value) check_expression - this is the … [Read more...] about Using ISNULL in SQL Server to Replace NULL Values

Using SQL COALESCE to Find the First Non-NULL Value

May 10, 2017 by Andy Hayes 1 Comment

SQL COALESCE example

You are looking to find a way to find the first non-null value from a list of fields. In this post, we look at SQL COALESCE - a wonderfully useful tool that helps to solve that problem. To help demonstrate this, we will talk about a hypothetical scenario where a number of customer leads have been added to a table from different sources and the consistency of data found in … [Read more...] about Using SQL COALESCE to Find the First Non-NULL Value

T-SQL – How to Select Top N Rows for Each Group Using ROW_NUMBER()

July 11, 2015 by Andy Hayes 19 Comments

I've recently been working on a data migration project and have found myself utilizing the ROW_NUMBER() function in SQL Server a lot. This function has been around since SQL Server 2005 and at its core, provides a way to provide sequential numbering for rows returned by a query. One of the requirements for an export process was to return the most recent two customer … [Read more...] about T-SQL – How to Select Top N Rows for Each Group Using ROW_NUMBER()

Data Management – Finding, Removing Duplicate Rows Using SQL and Some Prevention Tips

July 4, 2015 by Andy Hayes 2 Comments

find and remove duplicate data

Duplicate data is a common problem and in my experience comes in two main flavours; exact duplicate data and similar data. Exact duplicate data is when a data source contains the same values across all fields in the record. Similar data is when some of the fields match and to the naked eye can be classed as duplicate data but in fact it isn't - it's similar data and therefore … [Read more...] about Data Management – Finding, Removing Duplicate Rows Using SQL and Some Prevention Tips

Next Page »

Primary Sidebar

Categories

  • All Articles (82)
  • Career Development (8)
  • MySQL Administration (18)
  • MySQL Performance (2)
  • SQL Server Administration (24)
  • SQL Server News (3)
  • SQL Server Performance (14)
  • SQL Server Security (3)
  • SQL Tips and Tricks (19)

Top 10 Popular Posts

  • Using sp_change_users_login to fix SQL Server orphaned users
  • MySQL SHOW USERS? – How to List All MySQL Users and Privileges
  • How to shrink tempdb
  • How to Transfer Logins to Another SQL Server or Instance
  • How to Delete Millions of Rows using T-SQL with Reduced Impact
  • T-SQL – How to Select Top N Rows for Each Group Using ROW_NUMBER()
  • New T-SQL features in SQL Server 2012 – OFFSET and FETCH
  • How to Kill All MySQL Processes For a Specific User
  • Using exec sp_who2 to help with SQL Server troubleshooting
  • How to move tempdb

Recent Posts

  • How to Setup MySQL Master Master Replication
  • How To Use SQL to Convert a STRING to an INT
  • How to set up MySQL Replication Tutorial
  • How to Use SQL CASE for Conditional Logic in Your SQL Queries
  • Using ISNULL in SQL Server to Replace NULL Values

Search

Connect

  • Twitter
  • Facebook
  • Google+
  • RSS

About

  • Cookie Policy
  • Disclaimer
  • About
Copyright ©