Solved

Joint Syntax Error

Posted on 2006-11-21
7
266 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
Comment Utility
what kind of error are you getting.
0
 
LVL 29

Expert Comment

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

Expert Comment

by:QPR
Comment Utility
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 13

Accepted Solution

by:
Wizilling earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
good spotting
0
 
LVL 40

Expert Comment

by:Vadim Rapp
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now