Solved

Joint Syntax Error

Posted on 2006-11-21
7
275 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

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…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

740 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