• Skip to main content
  • Skip to primary sidebar

DBA Diaries

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

sql server

How to fix “conversion failed when converting date and/or time from character string”

April 30, 2023 by Andy Hayes Leave a Comment

Bad data - it's everywhere and a common problem is badly formatted dates. "conversion failed when converting date and/or time from character string" is the message returned in such situations. It's not unique to SQL and will be seen in other languages such as Python, C#, Java and others. In this post, we look at the why and how you can fix it. Getting to the bottom of … [Read more...] about How to fix “conversion failed when converting date and/or time from character string”

Using SQL GROUPING SETS for Multiple GROUP BY Queries in a Single Query

April 30, 2023 by Andy Hayes Leave a Comment

sql grouping sets

SQL GROUPING SETS is a feature of the SQL language that allows you to specify multiple group by sets in a single query. The best way to demonstrate this is with code and examples. So imagine you have table of sales data which contained the following fields: product region sale_amount A visual of this would look like: Now say you had a requirement to … [Read more...] about Using SQL GROUPING SETS for Multiple GROUP BY Queries in a Single Query

How To Use SQL to Convert a STRING to an INT

November 25, 2017 by Andy Hayes Leave a Comment

sql convert string to int

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

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 det … [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

Next Page »

Primary Sidebar

Categories

  • All Articles (84)
  • 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 (21)

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
  • Using exec sp_who2 to help with SQL Server troubleshooting
  • How to Kill All MySQL Processes For a Specific User
  • How to fix “conversion failed when converting date and/or time from character string”

Recent Posts

  • How to fix “conversion failed when converting date and/or time from character string”
  • Using SQL GROUPING SETS for Multiple GROUP BY Queries in a Single Query
  • 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

Search

Connect

  • Twitter
  • Facebook
  • RSS

About

  • Cookie Policy
  • Disclaimer
  • About
Copyright ©