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.
| 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 recommendedI think only way is Dynamic SQLDeclare @view varchar(30)set @view='yourViewName'Exec('Select columns from '+@view)MadhivananFailing to plan is Planning to fail |
 |
|
|
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 sysobjectsthis piece of code returns the code for the view "Store"select c.text from syscomments cjoin sysobjects o on c.id = o.id and o.xtype = 'V' and o.name = 'Store'Duane. |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-09-23 : 09:09:23
|
| see: sp_helptextThat 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. |
 |
|
|
|
|
|