Pass parameter to nested view?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Forgone Conclusion

    Pass parameter to nested view?

    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?
  • Simon Hayes

    #2
    Re: Pass parameter to nested view?


    "Forgone Conclusion" <basscadets@hot mail.com> wrote in message
    news:dc902814.0 401160456.18305 e23@posting.goo gle.com...[color=blue]
    > 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?[/color]

    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('200 40101', '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


    Comment

    • --CELKO--

      #3
      Re: Pass parameter to nested view?

      VIEWS do not take parameters. You will probably have to write it out
      as one statement without views in a stored procedure. We can nly gues
      without seeing the actual code, of course.

      Comment

      Working...