Using excel 2007 i'm trying to grab some data but my sql is erroring
i want to select max subs and platform as two different objects, this works with subs only but not with two!rst.Open "Select (MAX([Subscriber %]) as pc, Platform as plt) from Package WHERE [ID] IN (" & Join(Application.Transpose(idt), ",") & ") and [Digital/Analogue] = 'Digital' and Operator = 'BSkyB' and Country = '" & cntry & "'", conn
thanks
Jonathan
My guess would be the array is the problem, as SQL will not understand that string. Maybe each element needs single quotes around them if they are strings.
The array idt?
this doesn't seem to be at fault, as when i remove the platform as plt the statement executes correctly..
i was thinking i must have the syntax for selecting multiple columns as xx must be off
thanks
I suspect your issue is a lack of GROUP BY clause - I can't recall your Platform but in MySQL pseudo-syntax terms:
SELECT MAX(field1), field2 FROM table WHERE test GROUP BY field1 ORDER BY field1 DESC limit 1
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Hmm ok.. well thanks guys i just created two separate statements that does the same, it's a bit messy, but does the job
thanks for your time
Jonathan
erm, did you actually try the GROUP BY ?
Trust me - you do not need to run 2 separate queries
I would say that you post quite a few SQL syntax related questions - it would be well worth investing in an appropriate reference book
(eg SAMS "Teach yourself SQL in 10 minutes" etc...)
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Hi,
yeah i had a go at group by but not much luck i'm afraid...
the suggestion of a book is not bad at all
i,m using vba in excel for a access db.. so i'll go check out Amazon methinks
thanks
Jonathan
FWIW, the GROUP BY should work if you do it properly.![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks