explanation of if isnull sql statement

Posted on 2014-03-27
Medium Priority
Last Modified: 2014-03-27
Could somebody clarify what is going on in this statement. The part that I am not sure about is...at the end  ,' ') = ' '

if isnull(@filename_to_import,' ') = ' '

Question by:tesla764
  • 2
LVL 15

Assisted Solution

tim_cs earned 800 total points
ID: 39960022
It's checking to see if @filename_to_import is NULL or an empty string.

ISNULL() checks the first value @filename_to_import, if it is NULL then it returns whatever is in the second half, in this case an empty string.  If it's not NULL then it will return whatever value @filename_to_import is.
LVL 66

Accepted Solution

Jim Horn earned 1200 total points
ID: 39960030
> isnull(@filename_to_import,' ')
Return either the contents of the @filename_to_import variable if it's not NULL, or return a single space ' '.   This approach is useful when you want to weed out NULLs early before doing expressions.

>if isnull(@filename_to_import,' ') = ' '
If the @filename_to_import variable contains either NULL or '', then do whatever is below that line, such as..
if isnull(@filename_to_import,' ') = ' '
   -- There's no file name to import.  
   -- Either do an alternate thing, or end the sp. 
   --  There's a file name to import.  Rock on. 

Open in new window


Author Closing Comment

ID: 39960039
Thanks Everybody. That was very helpful.
LVL 66

Expert Comment

by:Jim Horn
ID: 39960084
Thanks for the split.  Good luck with your project.  -Jim

Featured Post

Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
In this article, we will see two different methods to recover deleted data. The first option will be using the transaction log to identify the operation and restore it in a specified section of the transaction log. The second option is simpler and c…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Screencast - Getting to Know the Pipeline

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question