Solved

Cannot see the error in this can anyone lend tips on how to troubleshoot SQL.

Posted on 2013-10-25
11
295 Views
Last Modified: 2013-10-26
Spent the last hour trying to find the error.....?

Msg 170, Level 15, State 1, Procedure Rpt_SnyderAccount_PL_Summary_RB, Line 40
Line 40: Incorrect syntax near '.'.


USE [WebSnakDS_SNYB_Test]
GO
/****** Object:  StoredProcedure [dbo].[Rpt_SnyderAccountP&LSummary_RB]    Script Date: 10/22/2013 11:47:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--Declare 
	ALTER PROCEDURE [dbo].[Rpt_SnyderAccount_PL_Summary_RB] 
	(
	@DB_Include			int -- 0 = Macola Only, 1 = RAMS Only, 2 = Macola and RAMS 

	) AS
-----------------------------------------------------------------------------------
-- Creating TEMP Table Bringing Macola RAMS and WebSNAK together
-----------------------------------------------------------------------------------

CREATE TABLE #TEMPTABLE
		
(
	[Data_Source] VARCHAR(12),--  what database is the data coming from  macola or rams?
	[InvoiceDate] DATETIME,
	[SNAK_SaleTypesID] CHAR (1),
	[CustPromoAmt] MONEY,
	[MFGCostAmt] MONEY, 
	[GrossAmt] MONEY,
	[CustName] VARCHAR(30),
	[SNAK_CustomerID] VARCHAR(8),
	[CHAINNAME] VARCHAR(30),
	[SNAK_CHAINID] VARCHAR(10)
	
	
)

 
-----------------------------------------------------------------------------------
-- WEBSNAK DATA
-----------------------------------------------------------------------------------

if (@DB_Include = 0 or @DB_Include = 2) -- 1 = RAMS Data only; 2 = Both WebSNAK and RAMS data
	BEGIN
	
insert  INTO #TEMPTABLE

SELECT
	'WEBSNAK'
	Invoices.InvoiceDate,
	InvoiceDetails.SNAK_SaleTypesID, 
	InvoiceDetails.CustPromoAmt,
	InvoiceDetails.MfgCostAmt,
	InvoiceDetails.GrossAmt,
	Customers.CustName, 
	Customers.SNAK_CustomerID,
	Chains.ChainName, 
	Chains.SNAK_ChainID
FROM
    { oj ((dbo.Invoices Invoices 
     INNER JOIN dbo.Customers Customers 
			ON	Invoices.Customers_Syskey = Customers.Customers_Syskey)
     INNER JOIN dbo.InvoiceDetails InvoiceDetails 
			ON	Invoices.Invoices_Syskey = InvoiceDetails.Invoices_Syskey)
     INNER JOIN dbo.Chains Chains 
			ON	Customers.Chains_Syskey = Chains.Chains_Syskey}

Open in new window

0
Comment
Question by:ruavol2
  • 3
  • 3
  • 3
  • +2
11 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 200 total points
ID: 39601230
Try removing all the parens from around the FROM clause:

FROM
    dbo.Invoices Invoices 
     INNER JOIN dbo.Customers Customers 
	 ON	Invoices.Customers_Syskey = Customers.Customers_Syskey
     INNER JOIN dbo.InvoiceDetails InvoiceDetails 
	 ON	Invoices.Invoices_Syskey = InvoiceDetails.Invoices_Syskey
     INNER JOIN dbo.Chains Chains 
	 ON	Customers.Chains_Syskey = Chains.Chains_Syskey

Open in new window

0
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 200 total points
ID: 39601238
>    { oj ((dbo.Invoices Invoices
What's the squiggly left parenthesis mark doing there?   Delete all parentheses, squiggly or otherwise, in your FROM .. JOIN block.

>      'WEBSNAK'
Missing a comma here
0
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 200 total points
ID: 39601243
>insert  INTO #TEMPTABLE
Also it's considered a poor programming practice to do an INSERT INTO table and not spell out all the columns, as that places a dependancy on the SELECT clause having ALL columns in EXACTLY the same order that it appears in #TEMPTABLE.  Any deviaiton from this will throw an error.
0
 
LVL 11

Assisted Solution

by:Simone B
Simone B earned 100 total points
ID: 39601247
In addition to all of the above, you seem to have a BEGIN without a corresponding END:

if (@DB_Include = 0 or @DB_Include = 2) -- 1 = RAMS Data only; 2 = Both WebSNAK and RAMS data
	BEGIN
	
insert  INTO #TEMPTABLE

SELECT
	'WEBSNAK',
	Invoices.InvoiceDate,
	InvoiceDetails.SNAK_SaleTypesID, 
	InvoiceDetails.CustPromoAmt,
	InvoiceDetails.MfgCostAmt,
	InvoiceDetails.GrossAmt,
	Customers.CustName, 
	Customers.SNAK_CustomerID,
	Chains.ChainName, 
	Chains.SNAK_ChainID
FROM
     dbo.Invoices Invoices 
     INNER JOIN dbo.Customers Customers 
			ON	Invoices.Customers_Syskey = Customers.Customers_Syskey
     INNER JOIN dbo.InvoiceDetails InvoiceDetails 
			ON	Invoices.Invoices_Syskey = InvoiceDetails.Invoices_Syskey
     INNER JOIN dbo.Chains Chains 
			ON	Customers.Chains_Syskey = Chains.Chains_Syskey
			
			END

Open in new window

0
 

Author Comment

by:ruavol2
ID: 39601263
I did not show the END at the end but it was in there.

Also it's considered a poor programming practice to do an INSERT INTO table and not spell out all the columns, as that places a dependancy on the SELECT clause having ALL columns in EXACTLY the same order that it appears in #TEMPTABLE

I did spell them out EXACTLY unless it is CASE SENSITIVE.....is it CASE SENSITIVE...?

Sqwiggly came from Crystal Reports....I stole some of the code in the beginning so I can learn. Unfortunately for me I have a hard time with picking things up without just doing it. I tried reading books in order to deal with women.....that did not work out so I just dove in and figured it out that way. Sometimes you just have to get your hands dirty.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 33

Assisted Solution

by:knightEknight
knightEknight earned 200 total points
ID: 39601270
>> is it CASE SENSITIVE...?

That depends on how your administrator configured the server.  One way to find out is to do this:

select top 1 * from dbo.Customers
select top 1 * from dbo.CUSTOMERS

If you get results from both queries, it is not case-sensitive.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 39601273
(well, unless you have two tables, one called Customers and the other CUSTOMERS ;)
0
 

Author Comment

by:ruavol2
ID: 39601303
It was the missing comma. Cannot believe I missed that......jeeese louise....!
Thanks
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39601305
>     INNER JOIN dbo.InvoiceDetails InvoiceDetails
btw using an alias that is exactly the same name as the table kinda defeats the purpose of the alias.  Better would be i for invoices, c for customers, id for invoice details, and ch for chains.  Much easier to read.
0
 

Author Closing Comment

by:ruavol2
ID: 39601315
I checked the Parenthesis and French Braces they are all okay. There was an end....just did not copy down that far....I have everything else commented out.....It was the comma.
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39603470
>>It was the missing comma. Cannot believe I missed that......jeeese louise....!
if only I had one cent per that problem, and it is why I recommend "comma first", like so:
SELECT
        'WEBSNAK'
      , Invoices.InvoiceDate
      , InvoiceDetails.SNAK_SaleTypesID
      , InvoiceDetails.CustPromoAmt
      , InvoiceDetails.MfgCostAmt
      , InvoiceDetails.GrossAmt
      , Customers.CustName
      , Customers.SNAK_CustomerID
      , Chains.ChainName
      , Chains.SNAK_ChainID
FROM dbo.Invoices Invoices
        INNER JOIN dbo.Customers Customers
                ON Invoices.Customers_Syskey = Customers.Customers_Syskey
        INNER JOIN dbo.InvoiceDetails InvoiceDetails
                ON Invoices.Invoices_Syskey = InvoiceDetails.Invoices_Syskey
        INNER JOIN dbo.Chains Chains
                ON Customers.Chains_Syskey = Chains.Chains_Syskey

Open in new window

I don't expect to convert all, but I have converted many :)
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now