Solved

explanation of if isnull sql statement

Posted on 2014-03-27
4
265 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
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 65

Accepted Solution

by:
Jim Horn earned 300 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 65

Expert Comment

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

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
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…

777 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