"Forgone Conclusion" <ba********@hotmail.com> wrote in message
news:dc**************************@posting.google.c om...
Hi,
I have a View that groups and sums up totals.
This View is then nested within in another View and used (it needs to
be done like this). What i need to do is to be able to vary the
records in the nested query by specifying dates. These would somehow
need to be passed to the nested query.
I've looked into stored procedures/functions but am still stumped on
how to do this.
Can anyone help?
Without your view definitions, it's not possible to give a good answer, but
in general most views can be re-written as table-valued functions:
create view dbo.MyView
as
select DateColumn, col1, col2
from dbo.MyTable
select * from dbo.MyView where DateColumn between '20040101' and '20040131'
becomes
create function dbo.MyFunc (@date1 datetime, @date2 datetime)
returns table
as
return (
select DateColumn, col1, col2
from dbo.MyTable
where DateColumn between @date1 and @date2
)
select * from dbo.MyFunc('20040101', '20040131')
Functions can also be nested, if necessary. If this doesn't help, perhaps
you could post (simplified) view definitions (CREATE VIEW statements), and
someone may be able to help.
Simon