PDA

View Full Version : Want help on Select statement



JackkG
01-23-2015, 01:29 PM
Hi,


Can you help me out with this query below. I wanted to list all the data from "List" sheet into the Test2 sheet. But the criteria is what I'm stuck up with.


Here I want to select all the columns mentioned in the Select statement, where unique instance of CIDs listed in Test sheet will be equal to all the multiple instances of CIDs in List sheet.




sSQL = "Select " & _
"[Author], [Collection], [Ticker], [Pdate], [DocID], [CID]" & _
" From [Test$] Where" & _
" [Test$].[CID] =
[List$].[CompanyID];"


Can anyone help me out with the query, how the Select statement will be?


Thanks!

JackkG
01-23-2015, 01:33 PM
.

JKwan
01-23-2015, 03:11 PM
I don't know if this is what you wanted, goto TEST tab and see

JackkG
01-23-2015, 04:10 PM
JK,

Im wondering why this gives me syntax error on From clause...

sSQL = "Select " & _
"[Author], [Collection], [Ticker], [Pdate], [DocID], [CID]" & _
" From [Test$] " & _
" JOIN
[List$] ON [Test$].[CID] =
[List$].[CompanyID];"

mikerickson
01-23-2015, 04:51 PM
Cross posted
http://www.excelforum.com/excel-programming-vba-macros/1062244-need-help-with-select-statement-2.html

sassora
01-24-2015, 01:21 AM
I notice the string near the JOIN is over multiple lines.

sSQL = "Select " & _
"[Author], [Collection], [Ticker], [Pdate], [DocID], [CID]" & _
" From [Test$] " & _
" JOIN tablename ON [Test$].[CID] = tablename.[CompanyID];"


I think this forum displays
[List$] on separate lines for some reason so I have swapped it with tablename in the string