Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty statement in T-SQL

Is there an empty statement keyword in T-SQL in Sql Server 2005 or newer? Something like NULL statement in PL/SQL.

like image 617
ternyk Avatar asked Jul 13 '10 07:07

ternyk


People also ask

Is NULL or empty T SQL?

NULL is used in SQL to indicate that a value doesn't exist in the database. It's not to be confused with an empty string or a zero value. While NULL indicates the absence of a value, the empty string and zero both represent actual values.

Is Empty in SQL query?

The IS NULL constraint can be used whenever the column is empty and the symbol ( ' ') is used when there is empty value.

How do you set an empty value in SQL?

In this article, we will look into how you can set the column value to Null in SQL. update students set Gender = NULL where Gender='F'; SELECT * FROM students ; Output: Column value can also be set to NULL without specifying the 'where' condition.

What is blank value in SQL?

The SQL NULL is the term used to represent a missing value. A NULL value in a table is a value in a field that appears to be blank. A field with a NULL value is a field with no value. It is very important to understand that a NULL value is different than a zero value or a field that contains spaces.


2 Answers

You can declare a label to do nothing.

DECLARE @value INT  IF @value IS NULL BEGIN no_op1:  END 
like image 177
Martin Smith Avatar answered Sep 16 '22 17:09

Martin Smith


ugly happens sometimes. I believe their is a valid use. In a lengthy/complicated decision branching structure with several if else statements, some of those statements may contain conditions in which you specifically desire no action. You also don't want those condition falling thru do the default else, where certain work is done. In that case, it's a valid use.

Here are two ways to do this - see B and C

Declare @status as char(1)  set @status = 'D'  If (@status = 'A')     select 'Great!'  Else if (@status = 'B') begin     if null=null select null -- predicate never resolves true end  Else if (@status = 'C')     set @status = @status  -- set a variable to itself   Else     select 'Needs work!' 

Note, this is an over-simplified example. It is best used for readability when conditions are complex.

like image 34
JM. Avatar answered Sep 19 '22 17:09

JM.