I am new to SQL and want to execute a statement if condition is true, and another statement in case of false.
SQL Server 2012 Query
select
if s.SpecialInsttPlan = 'No'
BEGIN
(s.TotalBill - s.Advance) / s.Installments as Installment
else
'Special' as Installment
END
from
SalesInvoice s
left join
InstallmentPaymentHistory iph
on iph.SalesInvoiceID = s.SalesInvoiceID
where
iph.SalesInvoiceID = 41
group by
s.TotalBill,
s.Advance,
s.Installments
My query ends with following errors
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'if'.
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near 's'.
Please help to resolve it