+ Reply to Thread
Results 1 to 8 of 8

Thread: SQL select as

  1. #1
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    SQL select as

    Using excel 2007 i'm trying to grab some data but my sql is erroring

    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
    i want to select max subs and platform as two different objects, this works with subs only but not with two!

    thanks

    Jonathan

  2. #2
    Forum Guru Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    MS Excel 2010
    Posts
    2,247

    Re: SQL select as

    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.

  3. #3
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Re: SQL select as

    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

  4. #4
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: SQL select as

    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

  5. #5
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Re: SQL select as

    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

  6. #6
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: SQL select as

    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...)

  7. #7
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Re: SQL select as

    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

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: SQL select as

    FWIW, the GROUP BY should work if you do it properly.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0