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. retrieving View's SQL statement [modified]

retrieving View's SQL statement [modified]

Scheduled Pinned Locked Moved Database
databasesql-serversysadmintutorialquestion
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.
  • H Offline
    H Offline
    hamidreza_buddy
    wrote on last edited by
    #1

    hi how should i retrieve View's SQL statement in SQL Server. i am using OleDb and i want it to be compatible with all the data Systems. for example i can retrieve the Query statements from an Access database (with GetOleDbSchemaGuid() ) but i am not able to do it with SQL Server (it dowsnt support retrieving views that way). is there another way or a specific SQL statement to do so?? thanks in advance -- modified at 6:20 Monday 26th February, 2007

    M 1 Reply Last reply
    0
    • H hamidreza_buddy

      hi how should i retrieve View's SQL statement in SQL Server. i am using OleDb and i want it to be compatible with all the data Systems. for example i can retrieve the Query statements from an Access database (with GetOleDbSchemaGuid() ) but i am not able to do it with SQL Server (it dowsnt support retrieving views that way). is there another way or a specific SQL statement to do so?? thanks in advance -- modified at 6:20 Monday 26th February, 2007

      M Offline
      M Offline
      Mark J Miller
      wrote on last edited by
      #2

      I used profiler to create a trace of all the queries from SSMS to the database and came up with this: SELECT ISNULL(smv.definition, ssmv.definition) AS [Definition] FROM sys.all_views AS v LEFT OUTER JOIN sys.sql_modules AS smv ON smv.object_id = v.object_id LEFT OUTER JOIN sys.system_sql_modules AS ssmv ON ssmv.object_id = v.object_id WHERE (v.type = 'V')and(v.name=N'{my_view_name}' and SCHEMA_NAME(v.schema_id)=N'dbo') Just replace {my_view_name} with the name of the view you're interested in. Also, if the view is using a schema other than 'dbo' make sure to change that as well.

      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