Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Parameters to a SQL View?

Parameters to a SQL View?

Scheduled Pinned Locked Moved Database
databaseperformancetutorialquestionlearning
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    keniagm
    wrote on last edited by
    #1

    Hi everybody, I'm using MSSQL2005 to build a report system and I need to create some views in order to speed up the execution of queries, but I need these views created so that the WHERE clause contains dynamic values, like parameters or so. If I write this as a simple query, it would be as follows: SELECT some_field FROM my_table WHERE another_field = @my_parameter of course, the query I want turned into a view is much more complex, but the point here is the WHERE part and the use of a parameter. So, I'm wondering if there's a way of using the view somehow that I can specify this parameter. If anyone knows if this can be done and how to do it, please, let me know. Thanks in advance Cheers,

    Kenia

    P 1 Reply Last reply
    0
    • K keniagm

      Hi everybody, I'm using MSSQL2005 to build a report system and I need to create some views in order to speed up the execution of queries, but I need these views created so that the WHERE clause contains dynamic values, like parameters or so. If I write this as a simple query, it would be as follows: SELECT some_field FROM my_table WHERE another_field = @my_parameter of course, the query I want turned into a view is much more complex, but the point here is the WHERE part and the use of a parameter. So, I'm wondering if there's a way of using the view somehow that I can specify this parameter. If anyone knows if this can be done and how to do it, please, let me know. Thanks in advance Cheers,

      Kenia

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      SQL Server doesn't support parameterized views. However you can achieve the same result with a table-valued user-defined function. See this article[^] for more information.

      Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups