Solved

Joint Syntax Error

Posted on 2006-11-21
7
279 Views
Last Modified: 2008-02-01
Hi,

I'm having the hardest time with a Select Statement, can someone please tell me what's wrong?  I could have trimmed down the fields, but since I don't know where the problem is, I left everthing verbatim.  Thank you!

Kathy

stSQL = "Select * From (SELECT PRODUCT_NAME,PRODUCT_LOCATION, INTERVAL_NAME, VM_VMONTH, SUM(UNREALIZED_VOLUME) as QUANTITY, SUM(GAMMA) as GAMMA_QUANT FROM Positions_20060808.csv WHERE TRANSACTION_BOOK_ID IN (238, 227, 168, 230, 193, 225,169, 119, 254) AND UNREALIZED_VOLUME is not null and GAMMA is not null GROUP BY PRODUCT_NAME, PRODUCT_LOCATION, INTERVAL_NAME, VM_VMONTH) As a" & _

"LEFT OUTER JOIN Select * From (SELECT ROW_NUM, PRODUCT_NAME, PRODUCT_LOCATION, INTERVAL_NAME, VM_VMONTH , LAST_PRICE, HIST_VOL FROM VolTable20060808.csv) As b " & _

"ON a.PRODUCT_NAME = b.PRODUCT_NAME and a.PRODUCT_LOCATION = b.PRODUCT_LOCATION and a.INTERVAL_NAME = b.INTERVAL_NAME and a.VM_VMONTH = b.VM_VMONTH ORDER BY b.ROW_NUM ASC"
0
Comment
Question by:KathySun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 13

Expert Comment

by:Wizilling
ID: 17991942
what kind of error are you getting.
0
 
LVL 29

Expert Comment

by:QPR
ID: 17991971
should stSQL be @stSQL?
have you declared the variable?
0
 
LVL 29

Expert Comment

by:QPR
ID: 17992021
also if this is a view/stored procedure then it should be

set @stSQL = 'select.......'

Notice also it is single quotes not doubles.
Are you doing this in SQL or in a web/desktop app?
0
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 
LVL 13

Accepted Solution

by:
Wizilling earned 125 total points
ID: 17992106
i think its a vb code and the sql is being passed as a vb parameter.

try this

stSQL = "Select * From (SELECT PRODUCT_NAME,PRODUCT_LOCATION, INTERVAL_NAME, VM_VMONTH, SUM(UNREALIZED_VOLUME) as QUANTITY, SUM(GAMMA) as GAMMA_QUANT FROM Positions_20060808.csv WHERE TRANSACTION_BOOK_ID IN (238, 227, 168, 230, 193, 225,169, 119, 254) AND UNREALIZED_VOLUME is not null and GAMMA is not null GROUP BY PRODUCT_NAME, PRODUCT_LOCATION, INTERVAL_NAME, VM_VMONTH) As a" & _

"LEFT OUTER JOIN (SELECT ROW_NUM, PRODUCT_NAME, PRODUCT_LOCATION, INTERVAL_NAME, VM_VMONTH , LAST_PRICE, HIST_VOL FROM VolTable20060808.csv) As b " & _

"ON a.PRODUCT_NAME = b.PRODUCT_NAME and a.PRODUCT_LOCATION = b.PRODUCT_LOCATION and a.INTERVAL_NAME = b.INTERVAL_NAME and a.VM_VMONTH = b.VM_VMONTH ORDER BY b.ROW_NUM ASC"
0
 
LVL 32

Expert Comment

by:bhess1
ID: 17992521
The problem is actually simpler than you think.  When the string is constructed, the resulting SQL Statement is illegal.  Add a space at the end of the first block of text.

As a" & _   <<<<Wrong

As a " & _  <<<<Right
0
 
LVL 29

Expert Comment

by:QPR
ID: 17992582
good spotting
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 17992687
stsql = _
"Select * From " & _
"(SELECT PRODUCT_NAME,PRODUCT_LOCATION, INTERVAL_NAME, VM_VMONTH, " & _
"SUM(UNREALIZED_VOLUME) as QUANTITY, SUM(GAMMA) " & _
"as GAMMA_QUANT FROM Positions_20060808.csv " & _
"WHERE TRANSACTION_BOOK_ID IN (238, 227, 168, 230, 193, 225,169, 119, 254) " & _
"AND UNREALIZED_VOLUME is not null " & _
"and GAMMA is not null GROUP BY PRODUCT_NAME, PRODUCT_LOCATION, INTERVAL_NAME, VM_VMONTH) As a " & _
"LEFT OUTER JOIN " & _
"(SELECT ROW_NUM, PRODUCT_NAME, PRODUCT_LOCATION, INTERVAL_NAME, VM_VMONTH , LAST_PRICE, HIST_VOL " & _
"FROM VolTable20060808.csv) As b " & _
"ON a.PRODUCT_NAME = b.PRODUCT_NAME and a.PRODUCT_LOCATION = b.PRODUCT_LOCATION and a.INTERVAL_NAME = b.INTERVAL_NAME " & _
"and a.VM_VMONTH = b.VM_VMONTH " & _
"ORDER BY b.ROW_NUM ASC"
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

726 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