We help IT Professionals succeed at work.
Get Started

SQL Syntax Errors

384 Views
Last Modified: 2013-11-26
Good Day:

I am using VB.NET with SQL Server 2000.  The following SQL has syntax errors:



SELECT dbo.SOShip.Company, dbo.SOHeader.SONumber, dbo.SOHeader.CustomerPO, dbo.SOHeader.OrderDate, dbo.SOHeader.ShipDate,
                      dbo.SOHeader.InvoiceNumber, dbo.SOHeader.OrderType
SELECT dbo.SOShip.Company, dbo.SOHeader.SONumber, dbo.SOHeader.CustomerPO, dbo.SOHeader.OrderDate, dbo.SOHeader.ShipDate, dbo.SOHeader.InvoiceNumber, dbo.SOHeader.OrderType, Case OrderType When 'INV' then InvoiceNumber When 'ORD' then '' When 'CAN' then 'CANCEL' End As Status FROM dbo.SOHeader LEFT OUTER JOIN dbo.SOShip ON dbo.SOHeader.SONumber = dbo.SOShip.SONumber Where [Company] like '%TOMM%' ORDER BY OrderDate DESC        



The following are my syntax errors:


Server: Msg 107, Level 16, State 3, Line 1
The column prefix 'dbo.SOShip' does not match with a table name or alias name used in the query.
Server: Msg 107, Level 16, State 1, Line 1
The column prefix 'dbo.SOHeader' does not match with a table name or alias name used in the query.
Server: Msg 107, Level 16, State 1, Line 1
The column prefix 'dbo.SOHeader' does not match with a table name or alias name used in the query.
Server: Msg 107, Level 16, State 1, Line 1
The column prefix 'dbo.SOHeader' does not match with a table name or alias name used in the query.
Server: Msg 107, Level 16, State 1, Line 1
The column prefix 'dbo.SOHeader' does not match with a table name or alias name used in the query.
Server: Msg 107, Level 16, State 1, Line 1
The column prefix 'dbo.SOHeader' does not match with a table name or alias name used in the query.
Server: Msg 107, Level 16, State 1, Line 1
The column prefix 'dbo.SOHeader' does not match with a table name or alias name used in the query.


The following are the two tables I am using:
CREATE TABLE [dbo].[SOHeader] (
      [SONumber] [nvarchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [SOSuffix] [nvarchar] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [OrderType] [nvarchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [BillToNo] [nvarchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [ShipToNo] [nvarchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [CustomerPO] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [Buyer] [nvarchar] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [SalesDept] [nvarchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [SalesPerson] [nvarchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [BackorderFlag] [nvarchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [FOB] [nvarchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [Terms] [nvarchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [ShipVia] [nvarchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [InvoiceNumber] [nvarchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [ShipViaAlt] [nvarchar] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [RaytheonBillRef] [nvarchar] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [OrderDate] [smalldatetime] NULL ,
      [ShipDate] [smalldatetime] NULL ,
      [FaxDate] [smalldatetime] NULL ,
      [InvoicePrintedDate] [smalldatetime] NULL ,
      [PrintFlag] [int] NULL ,
      [Weight] [int] NULL ,
      [PackageCount] [int] NULL ,
      [TotalValue] [money] NULL ,
      [TotalCost] [money] NULL ,
      [ShippingCharges] [money] NULL ,
      [TaxCharges] [money] NULL ,
      [BillReference] [nvarchar] (1000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [Taxable] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [RaytheonContract] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [SOHeaderTimeStamp] [datetime] NULL ,
      [UserName] [nchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SOShip] (
      [SONumber] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [SOSuffix] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [Company] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [Addr1] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [Addr2] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [City] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [State] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [Zip] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

How do I fix my errors?

Thank You,
Denise
Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2010
Commented:
This problem has been solved!
Unlock 2 Answers and 5 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE