Views with parameters

  • Hi All,

    Iam using sql server 2005,can i create a view with parameters?

    i want to pass the parameter in order to get a set of records based on the parameter passed.

    I know that stored procedures can be used for this purpose. but just i thought why cant i use a view.

    Regards,

    Amit Kulkarni

  • Views cannot take parameters. If you need a view-like object that takes parameters, consider using a table-values user-defined function. Be careful, sometimes they have a bad impact on performance.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Like Gail said, they can be problematic. It's the multi-statement table valued functions that will really chew on you. The single statement ones generally will create a good execution plan and work well with your query. However, you should test everything. Don't assume.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

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

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