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

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

Fletcher BurdineTableau Trainer & Consultant Sales Exec.Asked:
Who is Participating?
 
knightEknightConnect With a Mentor Commented:
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
 
Jim HornConnect With a Mentor Microsoft SQL Server Developer, Architect, and AuthorCommented:
>    { 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
 
Jim HornConnect With a Mentor Microsoft SQL Server Developer, Architect, and AuthorCommented:
>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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Simone BConnect With a Mentor Senior E-Commerce AnalystCommented:
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
 
Fletcher BurdineTableau Trainer & Consultant Sales Exec.Author Commented:
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
 
knightEknightConnect With a Mentor Commented:
>> 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
 
knightEknightCommented:
(well, unless you have two tables, one called Customers and the other CUSTOMERS ;)
0
 
Fletcher BurdineTableau Trainer & Consultant Sales Exec.Author Commented:
It was the missing comma. Cannot believe I missed that......jeeese louise....!
Thanks
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>     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
 
Fletcher BurdineTableau Trainer & Consultant Sales Exec.Author Commented:
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
 
PortletPaulfreelancerCommented:
>>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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.