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 2005 Forums
 Transact-SQL (2005)
 Script view as..create to..new query window-by qry

Author  Topic 

asafg
Starting Member

39 Posts

Posted - 2008-12-14 : 10:53:25
Hi

In Microsoft SQL Management Studio the studio generated for me the script that can create the view I'm looking at:

I right click the view and then
> Script view as > Create To > New Query Editor Window.

and then I see the script e.g.

USE [DB_TEST]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[V_Test]
AS
SELECT * FROM DB_TEST.dbo.TABLE_TEST


How can I get the same result using code
whithout the studio help something like :

select ViewSource from viewsSources

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-12-14 : 11:05:32
use sp_helptext 'Viewname'
Go to Top of Page

asafg
Starting Member

39 Posts

Posted - 2008-12-14 : 11:31:31
thanks very much
I need the text result

and after you showed my the way

This guy gave me an excellent idea:
exec sp_helptext 'sp_helptext' 

from:
http://joseph.randomnetworks.com/archives/tag/sp_helptext/

I would prefer to just get a table - because I dont know how to work with stored procedures result- it there are any...
but the good side is that I'll have to learn ;)

So thanks again
Asaf
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-12-14 : 11:42:08
Your question is not clear as what you need.
Go to Top of Page

asafg
Starting Member

39 Posts

Posted - 2008-12-14 : 11:52:01
What I really need is a query (or a call to stored procedure/function)
that return the same result I get using the sp_helptext as a string or more likely as a table.
I want to display the text in a textbox.

I am using c# and I send queries to the DB which returns strings and mostly tables.
I know that there is a way to work with stored procedure but I never tried it before...

but this is out of the scope of this forum - and you sure helped me a lot.

From this point I will find the solution.
Thanks
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-12-14 : 11:58:52
Ok. You are looking for this.

create table #temp
(text varchar(max))

Insert #temp
Exec sp_helptext 'viewname'

select * from #temp
Go to Top of Page
   

- Advertisement -