Dear Experts,
I am a newbie and trying to learn sql queries.
The following query does not work, I know there is something wrong with the syntax.
Please help me in writing this query better.
Thanks in advance.
SET @QDate = 'Jun' + ' ' + '2013'SELECT st.ID, st.FirstName, st.LastName,
CASE
WHEN sf.SubFee <= 0
THEN
CASE
WHEN ss.JoinDate < DATEADD(MONTH, DATEDIFF(MONTH, 0, @QDate),0)+10
THEN su.DefaultSubFee
WHEN ss.JoinDate > DATEADD(MONTH, DATEDIFF(MONTH, 0, @QDate),0)+10 AND ss.JoinDate < DATEADD(MONTH, DATEDIFF(MONTH, 0, @QDate),0)+20
THEN su.DefaultSubFee*0.5
ELSE 0
END
WHEN sf.SubFee > 0
THEN
CASE
WHEN ss.JoinDate < DATEADD(MONTH, DATEDIFF(MONTH, 0, @QDate),0)+10
THEN sf.SubFee
WHEN ss.JoinDate > DATEADD(MONTH, DATEDIFF(MONTH, 0, @QDate),0)+10 AND ss.JoinDate < DATEADD(MONTH, DATEDIFF(MONTH, 0, @QDate),0)+20
THEN sf.SubFee*0.5
ELSE 0
END
ELSE 0
END [dd], SUM(dd+sf.RegFee) as total