SQL Null or Empty How to Check for Null or Empty Column in SQL Server SQL Training Online

Sharing buttons:

hey joy blue here and today I want to

talk about the sequel null or empty and

what do we mean by that well first of

all null is the absence of a value which

means we don't it doesn't actually equal

anything it means we do not have a value

in the database now with empty what

we're talking about is an empty string

and so you can see an empty string in

the case of sequel here would be

ticktick with nothing in it so a full

string is like if I put in Joey

now this string has four characters

right even if I put in some spaces

they're still characters in there

they're just spaces but an empty string

has nothing in it it's just a tick tick

but a null is actually the absence of a

value so let's take a quick look at a

table I put together called the vendor

table and this vendor table has the

vendor name and the email and I put a

couple values in there I put a null so

we don't have an email for the Intel and

an empty string for Oracle which means

we don't have an email for Oracle and

you will run into data like this almost

you know anywhere you go you end up with

some bad data somehow the bad data gets

into the database so this Oracle

probably should be in a null or they

both should be empty strings they should

be consistent well what do want how do

we keep from getting those or in

particular how do we get both the null

and the string it's empty string at the

same time well first when you put our

where clause on there and when you say

we're vendor email and in order to get

to null what we would do is say is null

so you don't put an equal sign in there

because nothing equals a notes unknown

we don't have a value for so we have to

say is null it's a special little

function and that will give us the null

now in order to get the empty string you

actually say equals tick tick that's an

empty string and there you go and if you

want to get both of them you can say

where the vendor email equals two

or vendor email equals I'm sorry is no

and there's that now there is a little

trick of what we can do here to kind of

combine it into one there's a function

out there that says that's is null and

if I use this function I can basically

check the vendor email and if it's null

I can make it tick tick and so every

time it sees when a null its gonna turn

it into an empty string and then I can

compare it to an empty string so let's

see if that actually works see it

brought back both of those I've seen

people use this inside of joins when

they need when they have that data and

they need to have a notable column

they're trying to join so anyways that's

the sequel Knoll or empty statement and

as always if you find this helpful

please leave a comment below click the

like button or subscribe to my channel

and you can also visit me at sequel

training online.com and I hope you

enjoyed this free video