?
Solved

Joint Syntax Error

Posted on 2006-11-21
7
Medium Priority
?
284 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
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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

850 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