Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Tech-Recipes.com - SQL Server - NULLIF Function
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
DECLARE @TestData TABLE ( Id INT IDENTITY, Name1 VARCHAR(255), Name2 VARCHAR(255) ); INSERT INTO @TestData SELECT 'Rush', 'Rush' UNION SELECT 'Alp', 'Alpha' UNION SELECT 'Nkit', 'Nkit' UNION SELECT 'shew', 'shewt'; SELECT Id, Name1, Name2, NULLIF(Name1,Name2) FROM @TestData; SELECT Id, Name1, Name2, CASE WHEN Name1 = Name2 THEN NULL Else Name1 END FROM @TestData;
View schema
Execution time: 0,02 sec, rows selected: 8, rows affected: 4, absolute service time: 0,16 sec
edit mode
|
history
Id
Name1
Name2
(No column name)
1
1
Alp
Alpha
Alp
2
2
Nkit
Nkit
NULL
3
3
Rush
Rush
NULL
4
4
shew
shewt
shew
Id
Name1
Name2
(No column name)
1
1
Alp
Alpha
Alp
2
2
Nkit
Nkit
NULL
3
3
Rush
Rush
NULL
4
4
shew
shewt
shew