Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 INNER JOIN Shortcut key in VBA

Author  Topic 

lampis
Starting Member

10 Posts

Posted - 2011-10-05 : 11:25:00
Hello,

I've been trying to use a shortcut key when working with INNER JOIN in my SQL query. It is possible to use when working in MS SQL Server 2008 but when I work in VBA I get an error message. I'm trying to import data from my SQL Server to an Excel sheet through VBA code.

This is my query:
'sql_q = "SELECT p.[Date], p.[Asset], p.[Value], c.[Value], p.[Value]*c.[Value] FROM [Prices] AS p INNER JOIN [Prices] AS c ON p.Date = c.Date WHERE p.[Market] = '" & ds & "' AND p.[Date] BETWEEN '" & date_start & "' AND '" & date_end & "' AND c.[Market] = 'Currency' AND c.[Asset] = '" & curr & "' ORDER BY [Asset], [Date]"'

As you can see, I take the values from the same table. I have the prices of my assets as well as my currency pairs in the same table. I want to convert currency, hence "p.[Value]*c.[Value]".

The error message I recieve is "[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'p'."

Do you know how to use INNER JOIN shortcut keys while working in VBA?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-12-06 : 05:55:14
Print what sql_q returns and make sure it doesn't have any error

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -