Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Null or empty check for a string variable

Tags:

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

I want to know whether the above piece of code works in checking if the variable is null or empty.

like image 937
Bharath Avatar asked Apr 18 '13 10:04

Bharath


People also ask

How do I check if a string is empty or null?

You can use the IsNullOrWhiteSpace method to test whether a string is null , its value is String. Empty, or it consists only of white-space characters.

How do you test if a string string is empty?

Java String isEmpty() Method The isEmpty() method checks whether a string is empty or not. This method returns true if the string is empty (length() is 0), and false if not.

Can a string be null and empty?

A string refers to a character's sequence. Sometimes strings can be empty or NULL. The difference is that NULL is used to refer to nothing. However, an empty string is used to point to a unique string with zero length.

Can a string variable be null?

“A null String is Java is literally equal to a reserved word “null”. It means the String that does not point to any physical address.” In Java programming language, a “null” String is used to refer to nothing. It also indicates that the String variable is not actually tied to any memory location.


2 Answers

Yes, that code does exactly that.

You can also use:

if (@value is null or @value = '') 

Edit:

With the added information that @value is an int value, you need instead:

if (@value is null) 

An int value can never contain the value ''.

like image 93
Guffa Avatar answered Sep 19 '22 10:09

Guffa


Use This way is Better

if LEN(ISNULL(@Value,''))=0               

This check the field is empty or NULL

like image 20
AnasChavadi Avatar answered Sep 23 '22 10:09

AnasChavadi