Solved

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

Posted on 2013-10-25
11
296 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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
 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert formula to max at a specific date by month 18 18
MS SQL with ODBC 5 36
Querying data from 3 SQL tables 2 32
SQL Query assistance 16 25
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

773 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