Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Joint Syntax Error

Posted on 2006-11-21
7
Medium Priority
?
282 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
Independent Software Vendors: 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!

 
LVL 13

Accepted Solution

by:
Wizilling earned 375 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:Brendt Hess
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

618 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