Question : Incorrect Syntax near 'GO'

Hi Guys

I have a VB app passing an SQL Command:

IF Exists(select * from sysobjects where name='qryWebContacts' and xtype='V')
DROP VIEW [dbo].[qryWebContacts]
Go
CREATE VIEW [dbo].[qryWebContacts]
AS
SELECT     strLogin AS LoginEmail, strPassword AS LoginPassword, ContactPK, CompanyFK
FROM         dbo.Contacts
WHERE     (NOT (strPassword IS NULL))

When I pass the string in VB to SQL Server it passes it like:

IF Exists(select * from sysobjects where name='qryWebContacts' and xtype='V') DROP VIEW [dbo].[qryWebContacts] Go CREATE VIEW [dbo].[qryWebContacts] AS SELECT strLogin AS LoginEmail, strPassword AS LoginPassword, ContactPK, CompanyFK FROM dbo.Contacts
WHERE     (NOT (strPassword IS NULL))

The VB app is a generic app which allows us to pass any commands (normally just update queries), but mine has multiple commands in one string and the GO command needs to be on a seperate line.  Otherwise I get the Incorrect Syntax Near 'GO' error.

I cannot reprogram the VB app (it is not mine) to send a carriage return, but I was wondering if there is anything I can do in SQL which would do the same thing?

Thanks in advance.


Derek.

Answer : Incorrect Syntax near 'GO'

you cannot just pass this code:

IF Exists(select * from sysobjects where name='qryWebContacts' and xtype='V')
DROP VIEW [dbo].[qryWebContacts]
Go
CREATE VIEW [dbo].[qryWebContacts]
AS
SELECT     strLogin AS LoginEmail, strPassword AS LoginPassword, ContactPK, CompanyFK
FROM         dbo.Contacts
WHERE     (NOT (strPassword IS NULL))

you have to make it into a stored procedure and then execute that stored procedure throught VB code
Random Solutions  
 
programming4us programming4us