Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL function that returns a views "SELECT" statement?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-09-23 : 07:27:45
Steve writes "Let's say I have a view "vMyView" that is "SELECT id,name FROM MyTable WHERE id=123"

Is there a system function that you pass the view name to and it returns "SELECT id,name FROM MyTable WHERE id=123" ??"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-23 : 07:31:19
Passing table, view and Database names are not usally recommended
I think only way is Dynamic SQL
Declare @view varchar(30)
set @view='yourViewName'
Exec('Select columns from '+@view)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2005-09-23 : 07:33:22
you can access this via the system tables - syscomments and sysobjects
this piece of code returns the code for the view "Store"


select c.text from syscomments c
join sysobjects o on c.id = o.id and o.xtype = 'V' and o.name = 'Store'


Duane.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-09-23 : 09:09:23
see:

sp_helptext

That does the trick. Though I love the ability to query system tables directly, that should be avoided in general since there is no guarantee that they will not change from version to version of SQL.
Go to Top of Page
   

- Advertisement -