I have the following table:
TestTable
ColumnA
Column1
Column2
Column3
Column4
I want to write a simple SQL statement that checks ColumnA and depending on whether it is null or not returns certain columns.
Something like (pseudo):
If ColumnA Is Null
SELECT ColumnA, Column1, Column2
FROM TestTable
Else
SELECT ColumnA, Column3, Column4
FROM TestTable
Any ideas?
Use SQL CASE expressions:
See:
CASE (SQL-Server Transact-SQL)
CASE Expressions (Oracle)