can i pass a parameter to the view of SQLSERVER 2000

  • Hi,

    Can u tell me how can i pass a parameter to the view of SQLSERVER 2000 database OR how to create view that could accept parameter. Details (PLZ)

     



    ..Better Than Before...

  • AFAIK views cannot accept parameters. Instead you can either use a store procedure or a function which can accept parameters.

  • What about patritioned view , can u help me on that?



    ..Better Than Before...

  • You can always use where clause to filter out the data. That is as good as a paramater.

    Partitioned view requires that you have check constraint on each table of view.

    create table SalesTill1999 ( Year int CHECK (Year  < 1999 ) , .... )

    create table Sales1999 ( Year int CHECK (Year  = 1999 ) , .... )

    create table Sales2000( Year int CHECK (Year  = 2000) , .... )

    create table Sales2001 ( Year int CHECK (Year  = 2001) , .... )

    then you create a view based on this 4 tables.

    create view Sales as select * from SalesTill1999 union select * from Sales1999 union select * from Sales2000 union select * from Sales2001

    evry time a qry refering to particular year is fired against this view, SQL will only use the necessary table only. Others will not be accessed.

    e.g. select * from Sales where year = 2000 will only access Sales2000 table.

     

     


    -- Amit



    "There is no 'patch' for stupidity."



    Download the Updated SQL Server 2005 Books Online.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply