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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create view in SQL using VBscript need Help

Status
Not open for further replies.

colby

Technical User
Jul 6, 2000
11
GB
I am trying to create a view on the server on the fly
I use the following on one line to test if the view exists before creating it

Connection.Execute ("if exists (select * from sysobjects where id = object_id(N'[dbo].[myview]') and OBJECTPROPERTY(id, N'IsView') = 1)
create View dbo.myview AS SELECT cp_id, container_id, cp_value FROM container WHERE (cp_id = 666)")

all I get Back is

Microsoft OLE DB Provider for SQL Server error '80040e14'
Incorrect syntax near the keyword 'View'.


/colby/newfund.asp, line 35

I have written it to SQL Query analyzer
and get the same messge.

I Know Create view must be the first statement in a query batch. But all I want is to check first.

Can anyone help?
Thanks
 
Are you using the Go keyword between batches?
 
HI, I would suggest putting it into a stored procedure then calling it from your asp, just a thought

tal McMahon
 
Thanks very much for the help but I came accross the answer by accident I got the script generator in server enterprise manager to script the view.
I now send it in two lines by using the drop view at the end of the first line.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top