0

I have this query and I get Incorrect Syntax Errors near ')' (end of CREATE TABLE) and near 'END'.

Now, this works fine if I remove the BEGIN and END lines but Im not entirely sure what's wrong with it as is.

Note: This is not the finished product as there is more that will go after this and a lot more that preceded it. This is just one part of a much larger project but the parts are fairly independent and nothing in this query relies on any other part other than the existance of that [ARCSCON] table.

Can anyone tell me what I'm doing wrong?

IF  EXISTS( SELECT * FROM sys.objects 
    WHERE OBJECT_ID = OBJECT_ID(N'[dbo].[ARCSCON]'))
BEGIN

CREATE TABLE  [tempSAItems](        
            [Id] int identity(44444,1),
            [Name] nvarchar(55),
            [Type] nvarchar(50) DEFAULT 'Service Agreement',
            [Inactive] bit DEFAULT '0',
            [Purchased] bit DEFAULT '0',
            [MSDS] bit DEFAULT '0',
            [IncomeAccountID] int DEFAULT '7',
            [LaborCoverd] bit DEFAULT '0',
            [PartsCoverd] bit DEFAULT '0',
            [LifeTime] bit DEFAULT '0',
            [TravelCoverd] bit DEFAULT '0',
            [NumVisits] int, --[DURATION]
            [bLaborItem] bit DEFAULT '0',
            [bDirectCost] bit DEFAULT '0',
            [bAddToSales] bit DEFAULT '0',
            [sCostingMethod] nvarchar(50) DEFAULT 'Average Cost')
GO

INSERT INTO [tempSAItems]([Name])
SELECT DISTINCT [SCHEDTYPE]
FROM [ARCSCON]
GO  


END
SJuan76
  • 24,532
  • 6
  • 47
  • 87
AGx-07_162
  • 301
  • 1
  • 3
  • 14

1 Answers1

1

As @LittleBoobyTables commented just Rid of the Go written at the middle.

IF  EXISTS( SELECT * FROM sys.objects 
    WHERE OBJECT_ID = OBJECT_ID(N'[dbo].[ARCSCON]'))
BEGIN

CREATE TABLE  [tempSAItems](        
            [Id] int identity(44444,1),
            [Name] nvarchar(55),
            [Type] nvarchar(50) DEFAULT 'Service Agreement',
            [Inactive] bit DEFAULT '0',
            [Purchased] bit DEFAULT '0',
            [MSDS] bit DEFAULT '0',
            [IncomeAccountID] int DEFAULT '7',
            [LaborCoverd] bit DEFAULT '0',
            [PartsCoverd] bit DEFAULT '0',
            [LifeTime] bit DEFAULT '0',
            [TravelCoverd] bit DEFAULT '0',
            [NumVisits] int, --[DURATION]
            [bLaborItem] bit DEFAULT '0',
            [bDirectCost] bit DEFAULT '0',
            [bAddToSales] bit DEFAULT '0',
            [sCostingMethod] nvarchar(50) DEFAULT 'Average Cost')
--GO
^Here

INSERT INTO [tempSAItems]([Name])
SELECT DISTINCT [SCHEDTYPE]
FROM [ARCSCON]
GO  


END
Prahalad Gaggar
  • 11,389
  • 16
  • 53
  • 71
  • This sort of worked but presented a new problem. Removing the GO was the solution but the problem is created was that the INSERT INTO statement no longer works because it attempts to use the table the CREATE TABLE is supposed to be creating. I suppose I just misunderstand the use of the IF, BEGIN, and END thing (I'm still learning). I intended to put a lot of things in between but I may not be able to. – AGx-07_162 Mar 18 '13 at 17:58