If statements in a SQL View or Query
Posted on 2007-10-10
I have a SQL Query
Select Amount,TransactionType from Transactions
I want to put a condition statement in the Query where if the TransactionType=Collected put the Amount field in a new column called collected and in the amount column.
So the SQL would be something like this
Select Amount ,TransactionType ,(If Transactiontype= 'Collected' then use amount) As Collected
I want to be able to do this in a view which is built up of a few tables.
I kept the SQL Statement simple as to get an Idea as how this is done.