I need to show where condition based on a transaction type(expense,loan,deposit etc).
if transaction type is not equal to ‘Loan’ then show the where condition(where amount>1000).
if transaction type is ‘Loan’ then there is no need for where condition.
The problem is For Transaction type ‘Loan’ the amount is null.
Here is my Query..But I am getting error. Help me what mistake I am doing here.
This query is part of a bigger Dynamic SQL.
@SQL=@SQL+' case when TransactionType=''Loan'' then ''null'' else TotalAmount > ' + @amount + ' end '
I don’t think you need a case statement.
where TransactionType = 'Loan' or (TransactionType <> 'Loan' and TotalAmount > @amount)
Also not sure if you need
TransactionType <> 'Loan'based on the limited query given.