Solved

explanation of if isnull sql statement

Posted on 2014-03-27
4
259 Views
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,' ') = ' '

Thanks
0
Comment
Question by:tesla764
  • 2
4 Comments
 
LVL 15

Assisted Solution

by:tim_cs
tim_cs earned 200 total points
Comment Utility
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.
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 300 total points
Comment Utility
> 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,' ') = ' '
   begin
   -- There's no file name to import.  
   -- Either do an alternate thing, or end the sp. 
   end 
ELSE 
   begin
   --  There's a file name to import.  Rock on. 
   end

Open in new window

0
 

Author Closing Comment

by:tesla764
Comment Utility
Thanks Everybody. That was very helpful.
0
 
LVL 65

Expert Comment

by:Jim Horn
Comment Utility
Thanks for the split.  Good luck with your project.  -Jim
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

728 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now