Select @sql='select SRegNo as RegNo,SEnglishName as Name,SClass,sDateofbirth as DateofBirth,Day(sDateofBirth)-Day(getdate()) as Noofdays from Student awhere -- Find next birthday after today case when dateadd(yy,datediff(yy,sDateofBirth,getdate()),sDateofBirth) > dateadd(dd,datediff(dd,0,getdate()),0) then dateadd(yy,datediff(yy,sDateofBirth,getdate()),sDateofBirth) else dateadd(yy,datediff(yy,sDateofBirth,getdate())+1,sDateofBirth) end between -- Tomorrow dateadd(dd,datediff(dd,0,getdate()),0) and -- Tomorrow plus 6 days dateadd(dd,datediff(dd,0,getdate())+@NoDay,0) Order By ' + @odBy

Select @sql='select SRegNo as RegNo,SEnglishName as Name,SClass,sDateofbirth as DateofBirth,Day(sDateofBirth)-Day(getdate()) as Noofdays from Student a
where
-- Find next birthday after today
case
when dateadd(yy,datediff(yy,sDateofBirth,getdate()),sDateofBirth) >
dateadd(dd,datediff(dd,0,getdate()),0)
then dateadd(yy,datediff(yy,sDateofBirth,getdate()),sDateofBirth)
else dateadd(yy,datediff(yy,sDateofBirth,getdate())+1,sDateofBirth)
end between
-- Tomorrow
dateadd(dd,datediff(dd,0,getdate()),0) and
-- Tomorrow plus 6 days
dateadd(dd,datediff(dd,0,getdate())' + @NoDay + ',0) Order By ' + @odBy