Tag: case

  • CASE Statement in SQL (Practical Examples)

    What is a SQL case statement? Well, it’s much like a switch statement in a development language. It allows you to test several different cases for a field and determine what you would like to do for each one with SQL Server.

    (more…)

  • MSSQL Running an extra AND statement

    This had me baffled and shook me to the core as it went against everything I understand about an AND statement. I was using a standard CASE as I have done hundreds, if not thousands, of times that contained two AND statements. The first part of the statement returned false but, MSSQL still proceeded to execute the second statement. This may not seem like a big deal, but in this particular case I had an error producing data type mismatch problem. When the first part of the CASE was true the second part compared the data as a bigint whereas the actual value was an nvarchar, so it errored.

    Let’s take a look at an example.

    (more…)