Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a view from a stored procedure 1

Status
Not open for further replies.

TomBarrand

Programmer
Joined
Aug 9, 2000
Messages
162
Location
GB
I would like to create a view from within a stored procedure, but the view name needs to be a variable that is passed into the stored procedure. Is this possible? If so some example syntax would be appreciated.

Cheers
 

You'll need to create and execute a dynamic SQL statement. Here is a simple example.

Create procedure CreateNewView @viewname nvarchar(128) As

Declare @sql nvarchar(2000)

Select @sql=
'Create View ' + @ViewName +
' As Select * From tableA'

Exec(@sql)

Go Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top