Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

explanation of if isnull sql statement

Posted on 2014-03-27
4
Medium Priority
?
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Assisted Solution

by:tim_cs
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.
0
 
LVL 66

Accepted Solution

by:
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,' ') = ' '
   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
ID: 39960039
Thanks Everybody. That was very helpful.
0
 
LVL 66

Expert Comment

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

618 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