mysql - How do I write cursor which is passed to other sql query? -
i have 1 select
statement gives me following result
masterid date 123 2012-10-15 00:00:00.000 124 2012-12-03 00:00:00.000 453 2012-01-07 00:00:00.000
(output having 1999 rows)
now need pass output 1 scalar value function gives takes parameters like
mycalculationfunction (@masterid,@date,@previousdate)
i want pass above values mycalculationfunction
can select function , see values each masterid
also need provide previousdate
there parameter.
so please me create cursor can use.
in sql server 2012:
select mycalculationfunction ( masterid, [date], lag([date]) on (order [date]) ) mytable m order [date]
in earlier versions:
select mycalculationfunction ( masterid, [date], ( select top 1 [date] mytable mi mi.[date] < m.[date] order mi.[date] desc ) ) mytable m order [date]