Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hello,I have Course table with different courses.. as belowCourseId CourseName Fees Months1 ABC 2000 22 XYZ 5000 4while applying this course to student i need installment entries..for that i need select Statement with help of months.. as belowoutput.. if user selects second(2) course then.. four installments as belowCourseId Coursename ToPayFees1 XYZ 12501 XYZ 12501 XYZ 12501 XYZ 1250Please help
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2010-03-13 : 11:00:42
How did courseId change to 1 in output? Assuming thats a typo, the solution you need is
SELECT c.CourseId,c.CourseName,c.Fees/Months AS ToPayFeesFROM Course cCROSS JOIN master..spt_values vWHERE v.type='p'AND v.number BETWEEN 1 AND c.MonthsAND c.CourseId=@CourseID
pass required course number into parameter like 1,2,...------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Sachin.Nand
2937 Posts
Posted - 2010-03-13 : 11:29:54
OR
;with cteas(select courseid,coursename,months,fees,1 as cntmonths from @tblunion allselect t1.courseid,t1.coursename,t1.months,t1.fees,cntmonths+1 from @tbl t1inner join cte on cte.cntmonths+1<=t1.monthswhere cte.courseid=t1.courseid)select courseid,coursename,fees/months as ToPayfees from cte t2 order by courseid
PBUH
keyursoni85
Posting Yak Master
233 Posts
Posted - 2010-03-13 : 12:44:35
what is this table used for..?master..spt_values vdidn't getting this ?result is same as i need..
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2010-03-13 : 14:21:27
quote:Originally posted by keyursoni85 what is this table used for..?master..spt_values vdidn't getting this ?result is same as i need..
thats an internal count table which is available in sql server.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
keyursoni85
Posting Yak Master
233 Posts
Posted - 2010-03-14 : 00:39:00
Thanks..visakh and idera
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2010-03-14 : 00:47:58
welcome ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/