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

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

January 24, 2013 by Joey Blue Leave a Comment

Simple Trick to Copy and Paste Web Data into SQL Server

When answering questions on forums or blogs, I often like to put the data into SQL Server where I can make sure my SQL works before I answer a question.

As you can imagine, I don’t want to spend a lot of time importing that data.

So, here is a little trick that you can use to copy and paste and HTML table into a SQL table without having to write insert statements or use the Import/Export wizard.

Video: SQL Server Import Data with Copy and Paste


How to Import Web Data into SQL Server with a simple copy and paste. No special import and export tools needed.

Youtube Video Location: Import HTML Table Data To SQL Server with Copy Paste

 

Here are a few other posts you might enjoy:

SQL Microsoft Excel to Windows Azure SQL in 10 minutes | Troubleshooting a SQL Join | How to Remove Duplicate Rows in SQL Server

 

You can visit me at any of the following:

SQL Training Online: https://www.sqltrainingonline.com

Twitter: http://www.twitter.com/sql_by_joey

Google+: https://plus.google.com/#100925239624117719658/posts

LinkedIn: http://www.linkedin.com/in/joeyblue

Facebook: http://www.facebook.com/sqltrainingonline

Filed Under: SQL Tip, SQL Training Tagged With: Import, SQL, SQL Import, SQL Server 2012, SSMS

  • « Previous Page
  • 1
  • 2
  • 3

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