Wiered Access Parsing thing happening

Joined
Oct 11, 2007
Messages
1
Reaction score
0
Ok, I have the following peice of code..to create a pass through query

strSQL = " select ISNULL(v.PAYEE_ADDRESS_1, v1.PAYEE_ADDRESS_1) as PAYEE_ADDRESS_1,ISNULL(v.PAYEE_ADDRESS_2,v1.PAYEE_ADDRESS_2) as PAYEE_ADDRESS_2, "
strSQL = strSQL & Chr$(13)
strSQL = strSQL & "ISNULL(v.PAYEE_CITY,v1.PAYEE_CITY) as PAYEE_CITY,"
strSQL = strSQL & Chr$(13)
strSQL = strSQL & "ISNULL(v.PAYEE_STATE,v1.PAYEE_STATE) as PAYEE_STATE, ISNULL(v.PAYEE_ZIP, v1.PAYEE_ZIP) as PAYEE_ZIP,"
strSQL = strSQL & Chr$(13)
strSQL = strSQL & "m.MEDIA_NAME, st.BAND_CODE,e.ESTIMATE_ID,cl.CLIENT_NAME, p.PRODUCT_NAME, st.CALL_LETTERS,"
strSQL = strSQL & Chr$(13)
strSQL = strSQL & " i.INVOICE_NUMBER,i.MATCHED_DATE, i.INVOICE_DATE, v.VENDOR_ID "
strSQL = strSQL & Chr$(13)
strSQL = strSQL & " FROM dbo.ESTIMATE AS e INNER JOIN dbo.SURVEY AS S ON e.ESTIMATE_ID = S.ESTIMATE_ID INNER JOIN "
strSQL = strSQL & Chr$(13)
strSQL = strSQL & " dbo.MEDIA AS m ON m.MEDIA_ID = e.MEDIA_ID INNER JOIN dbo.STATION AS st ON st.SURVEY_ID = S.SURVEY_ID INNER JOIN "
strSQL = strSQL & Chr$(13)
strSQL = strSQL & " dbo.INVOICE AS i ON i.STATION_ID = st.STATION_ID INNER JOIN dbo.INVOICE_DETAIL AS id ON id.INVOICE_ID = i.INVOICE_ID INNER JOIN "
strSQL = strSQL & Chr$(13)
strSQL = strSQL & " dbo.SPOT AS sp ON sp.SPOT_ID = id.MATCHING_SPOT INNER JOIN dbo.PRODUCT AS p ON e.PRODUCT_ID = p.PRODUCT_ID INNER JOIN "
strSQL = strSQL & Chr$(13)
strSQL = strSQL & " dbo.CLIENT AS cl ON p.CLIENT_ID = cl.CLIENT_ID INNER JOIN dbo.OFFICE AS o ON cl.OFFICE_ID = o.OFFICE_ID INNER JOIN"
strSQL = strSQL & Chr$(13)
strSQL = strSQL & " dbo.MARKET AS mkt ON S.MARKET_ID = mkt.MARKET_ID LEFT OUTER JOIN dbo.VENDOR AS v1 ON v1.VENDOR_ID = st.VENDOR_ID "
strSQL = strSQL & Chr$(13)
strSQL = strSQL & " LEFT OUTER JOIN dbo.STRATA_STATIONS AS ss ON ss.STRATA_STATION_ID = st.STRATA_STATION_ID LEFT OUTER JOIN "
strSQL = strSQL & Chr$(13)
strSQL = strSQL & " dbo.STRATA_TV_STATIONS AS stv ON stv.STRATA_STATION_ID = st.STRATA_STATION_ID LEFT OUTER JOIN "
strSQL = strSQL & Chr$(13)
strSQL = strSQL & " dbo.VENDOR AS v ON v.STRATA_STATION_ID = stv.STRATA_STATION_ID AND m.MEDIA_ID = v.MEDIA_ID "
strSQL = strSQL & Chr$(13)
strSQL = strSQL & " where e.ESTIMATE_ID = '" & " " & [Forms]![frmentry]![mEstimate] & "'"
strSQL = strSQL & Chr$(13)
strSQL = strSQL & " and id.SPOT_DATE_TIME between '" & " " & [Forms]![frmentry]![bdate1] & "'"
strSQL = strSQL & Chr$(13)
strSQL = strSQL & " And '" & " " & [Forms]![frmentry]![bdate2] & "'"

when i do this
Debug.Print strSQL
and take that syntax over to SQL server it works grand..however when I execute this piece of code..

Set qdExtData = .QueryDefs("PASS_THROUGH")

qdExtData.Connect = "ODBC;DSN=SBMSData;"
qdExtData.SQL = strSQL
Set rs = db.OpenRecordset(strSQL)

I get Syntax error on the sql. I believe it's because of how the SQL is being constructed when Access tries to send that SQL over to SQl server.

Any ideas on how to fix this..

Thanks

Sameer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top