+ Reply to Thread
Results 1 to 9 of 9

VBA/SQL Select problem

  1. #1
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    462

    VBA/SQL Select problem

    Hi all, could someone help with this please. I am running a report and simply trying to count the jobs and group by depot. This works fine but it pulls in a row for Depot5 (which we don't use anymore). when I put the WHERE clause in to exlude this depot, I end up with an empty row at the top with a zero in the count column. Not sure how to avoid this empty row?

    Please Login or Register  to view this content.
    Thanks
    John

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA/SQL Select problem

    What is the source of the data? Access, Excel MySQL?

    I tried using Access to test your problem, but within access the case function won't work, I tried this sql there and it returned no blank rows:
    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA/SQL Select problem

    I believe you should also be able to just to a count of a.JobType, and add a.JobType = 'Type1' to your WHERE clause.

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: VBA/SQL Select problem

    You should check your table.

    Since your syntax looks to be for SQL server. Ran it on test table and confirmed it returned no empty row.

    You can also try using SUM instead of count.
    Please Login or Register  to view this content.
    Edit: Removed unnecessary "," after 'Type1'
    Last edited by CK76; 01-25-2017 at 11:14 AM. Reason: See Edit:

  5. #5
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: VBA/SQL Select problem

    Not sure you need comma here:
    Please Login or Register  to view this content.

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: VBA/SQL Select problem

    Woops a typo. Edited code. Thanks for pointing it out

  7. #7
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: VBA/SQL Select problem

    Quote Originally Posted by CK76 View Post
    Since your syntax looks to be for SQL server.
    because I was participating in another thread - the database is visual foxpro
    If you are pleased with a member's answer then use the Star icon to rate it.

  8. #8
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    462

    Re: VBA/SQL Select problem

    Hi, thanks very much for the replies. It was a Sybase database that I was querying through ODBC/Excel. I actually have 6 depots and there are an additional 2 that I wanted to ignore. For some reason "<> these 2 depots" produced the blank header row but specifically choosing the correct depots (WHERE depot = depot1 OR depot2 OR depot3 OR depot4).... worked perfectly. Bit bizarre but got there in the end. :-)

    Thanks again for the replies.

  9. #9
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    462

    Re: VBA/SQL Select problem

    Hi, thanks very much for the replies. It was a Sybase database that I was querying through ODBC/Excel. I actually have 6 depots and there are an additional 2 that I wanted to ignore. For some reason "<> these 2 depots" produced the blank header row but specifically choosing the correct depots (WHERE depot = depot1 OR depot2 OR depot3 OR depot4).... worked perfectly. Bit bizarre but got there in the end. :-)

    Thanks again for the replies.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Select Case Problem
    By outofahat in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-12-2016, 02:14 PM
  2. [SOLVED] Select from second row to last in column A - problem
    By nkehayova in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-29-2015, 08:11 AM
  3. [SOLVED] Select Case problem
    By Darthzo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-28-2012, 11:49 AM
  4. Problem with VBA/ADO Select Into
    By JohnM3 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-16-2011, 12:06 PM
  5. select case problem
    By jippii in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-11-2011, 06:05 PM
  6. Column select problem
    By edhaddock in forum Excel General
    Replies: 2
    Last Post: 12-26-2006, 08:20 PM
  7. [SOLVED] Having Problem with Select Case
    By [email protected] in forum Excel General
    Replies: 2
    Last Post: 07-26-2006, 06:15 PM

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.6.0 RC 1