Using SQL to convert a string to an int is used in a variety of situations. You may have text data that you cannot alter at the source and you need to get some accurate answers from it. You may also have text data that you want to insert to an integer column. There could be other reasons too. There is an easy solution to this and I will show you examples in both SQL Server … [Read more...] about How To Use SQL to Convert a STRING to an INT
SQL Tips and Tricks
How to Use SQL CASE for Conditional Logic in Your SQL Queries
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
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
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()
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()