Telling data to act like other data

When messing with data, sometimes you want to change how SQL Server sees the data. For that, you would want to use the CONVERT command.

There are many great reasons to do this and thankfully some of our datasets have some great possibilities that you can work with.

For example, after looking at the Nirvana Performances data set, you probably noticed that some of the dates look “not-so-datey.”

If you want to try to change this data into a date that SQL Server sees as a date, then one of the possibilities you might want to try is the CONVERT command.

Guess not

Because of the “not-so-dateness” of the data, you cannot convert non-date items into a date, at least not with the CONVERT function.

On the other hand, you can do it with the TRY_CONVERT function.

No errors!

Now, even if it did work, you’ll notice there are these weird NULLs showing. Those just happen to be where the dates with question marks show.

Sadly, if you want to convert your “not-so-datey” dates into something that SQL Server sees as a date, then you’re going to be stuck with the TRY_CONVERT function.

Thankfully, as you’ve seen it’s very easy to use and is not very different from the CONVERT function.

Next time, we’ll go into different reasons to use the CONVERT and TRY_CONVERT functions and how they can make your life easier. Until next time my friends!

1 comment

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.