SQL Training Online

  • Training Courses
  • Beginner Book
  • Blog

August 26, 2017 by Joey Blue Leave a Comment

Format Function in SQL Server

The Format Function can help you change how a date or decimal is displayed.

In this video I do a quick demonstration of the Format Function.

Video: SQL Server Format Function


How to use the SQL Format Function on a Date.

I use the Wide World Importers and the following scripts:

select OrderDate,Format(OrderDate,'MMM dd, yyyy') 
from [Sales].[Orders]
where year(OrderDate) = 2016

Link to the Microsoft SQL Server Custom Date Formatters.

 

See the original  SQL Format for Date video.

Filed Under: SQL Tip Tagged With: date, datetime, SQL Datetime, SQL Server, SQL Where

August 24, 2017 by Joey Blue Leave a Comment

Union and Union All – How to use it in SQL Server

 

Union and Union All are very similar, but if you don’t understand the differences, it can cause trouble.

In this video I do a quick demonstration of the Union and Union All Function.

Video: SQL Server Union and Union All


How to use the SQL Server Union and Union All Operators to combine data sets.

I use the Wide World Importers and the following scripts:

select * from [Application].[People]
where PersonID between 1 and 5
union
select * from [Application].[People]
where PersonID between 4 and 9

 

See the original  SQL Union and Union All video.

Filed Under: SQL Tip Tagged With: SQL Between, SQL Server, Union, Union All

June 5, 2017 by Joey Blue Leave a Comment

Big Data Everywhere

Hey guys, I’m on ESPN.com today checking out Russell Westbrook’s 49 points in his return to the NBA after a freak accident.

Russell fell down and a teammate ran into him fracturing his jaw.But, despite surgery a few days ago, he came back with a mask and dropped 49 points.

Now, I’m not a huge Russell Westbrook fan, or a fan of the NBA in general, but that is a pretty cool story.

But, that isn’t what got my attention…

What really got my attention was the commercial that showed up on ESPN before the highlight.

It was about IBM analytics… Watson Analytics.

I thought, “Wow! Analytics and Big Data are main stream.”

It wasn’t normal consumer products like Insurance…

But, it was about data!

This is validation that the BI market is huge.

You don’t see commercials about .Net development, or Java development, but commercials about data and analytics.

You constantly see stuff in the news about Big Data and Analytics.

If the big companies are selling it, businesses need people like us to actually make them work.

This means jobs, higher demand, and ultimately money.

And, it doesn’t have to be crazy complex to get started.

Even the Big Data stuff ends up in relational databases.

If you haven’t checked out my 30 Free SQL videos yet, they have been moved to a free membership site.

You have to provide your email, but it is 100% free.

https://www.sqltrainingonline.com/30-free-videos/

Click it while it is still active.

In the member’s area, it is easier to find all of the videos and it also includes the practice database.

Sincerely,
Joey Blue

P.S.  Getting started with SQL is easiest by just starting with the SQL Query.  That is exactly what this training does.  Don’t wait any longer, start now.
https://www.sqltrainingonline.com/30-free-videos/

Filed Under: SQL Training

February 14, 2015 by Joey Blue Leave a Comment

How to use the SQL Server String Concat Function in SQL Server 2012

 

SQL Server 2012 includes a new Concat function that makes it easier to put strings, numbers, dates, and nulls together.

The old way was with ‘+’ signs and cast or convert.  Now you just use the SQL Server String Concat Function.

In this video I do a quick demonstration of the Concat Function.

Video: SQL Server String Concat


How to use the new SQL Server 2012 CONCAT Function to combine columns and strings.

I use the Chinook Sample Database and the following scripts:

select FirstName + ' ' + LastName + '-' + Company 
from customer

select CONCAT(FirstName,' ',LastName,'-',Company)
from customer

 

See the original  SQL Concat Function video.

Filed Under: SQL Tip Tagged With: SQL Concat, SQL Convert, SQL Server 2012, SQL String Concat

February 7, 2015 by Joey Blue Leave a Comment

How to Filter using SQL IsDate() Function and Cast

Video: SQL IsDate() Function as a Filter


Using the SQL IsDate() Function in your filter needs a little trick to make it work.

 

In your career you may run into an issue where you have a date stored as a varchar.

When this happens, you may need to use the SQL IsDate in the Where Clause.

You need to first use the SQL IsDate Function to check if the value is a valid date.

Then you can convert the varchar to a date using Cast or Convert.

Even though you have filtered on the SQL Isdate, you might still have a problem with the conversion.

This video shows you how to deal with it.

I don’t mention it in the video, but when dealing with dates, you always have to keep in mind the default date settings of the database.

Cast and Isdate use these defaults and could cause you some trouble if you aren’t aware of them.

Here are the scripts to run the queries that are in the video.

 

create table emp
(
id int primary key identity(1,1)
,emp_name varchar(50)
,emp_birthday varchar(20)
)
GO
insert into emp (emp_name,emp_birthday) values ('Bob','12/12/2001');
insert into emp (emp_name,emp_birthday) values ('Mary','123');
insert into emp (emp_name,emp_birthday) values ('Jill','12/1/2005');
insert into emp (emp_name,emp_birthday) values ('Jim','1/12/1999');
insert into emp (emp_name,emp_birthday) values ('Sue','7/15/2011');
insert into emp (emp_name,emp_birthday) values ('Sally','20120315');
GO

select id,emp_name,emp_birthday
,isdate(emp_birthday)
from emp
where isdate(emp_birthday)=1
and 
case when isdate(emp_birthday)=0 then cast(null as date)
    else cast(emp_birthday as date)
end < '1/1/2006'

Here is the YouTube Video SQL Isdate Function as a Filter with Cast .

Filed Under: SQL Tip Tagged With: SQL, SQL Case Statement, SQL Cast, SQL Convert, SQL Datetime, SQL Isdate

  • « Previous Page
  • 1
  • 2
  • 3
  • 4
  • 5
  • …
  • 10
  • Next Page »

Recent Posts

  • SQL Database Normalization – 1NF, 2NF, 3NF, and 4NF
  • SQL Joins Tutorial for Beginners – Inner Join, Left Join, Right Join, Full Outer Join – SQL Training Online
  • Zillow House Price Analysis from CSV Archive – #PowerBI 002
  • Learn Basic SQL – 1 Hour Training Course – SQL Training Online
  • Create Table Statement in SQL Server and Inserting Baseball Homerun Leader Dataset – SQL Training Online

Popular Posts

  • SQL Functions
  • SQL Jobs in Oracle and Microsoft SQL Server
  • Troubleshooting a SQL Join
Copyright © 2023 · SQLTrainingOnline.com · Consulting at EmbarkBlue.com