Results 1 to 6 of 6

Thread: [RESOLVED] COUNT DISTINCT & Progressbar Error

  1. #1

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Resolved [RESOLVED] COUNT DISTINCT & Progressbar Error

    Having much troubles with COUNT DISTINCT since yesterday and I can't find any solution on the internet. The weird thing is that I have several errors, but never on the same time. When I think I solved something another error pops.

    The SQL-command:
    Code:
    Dim cmd_plaats As New SqlCeCommand("SELECT DISTINCT plaats FROM beslagdata", connStr)
    Dim cmd_count_plaats As New SqlCeCommand("SELECT COUNT (plaats) FROM (SELECT DISTINCT plaats FROM beslagdata)", connStr)
    Code:
    With frm_main.ts_progress
        .Value = 0   '  reset the value
        .Maximum = Convert.ToInt32(cmd_count_plaats.ExecuteScalar)    '   count the records
    End With
    Details:
    Code:
    {"There was an error parsing the query. [ Token line number = 1,Token line offset = 68,Token in error = ) ]"}
    Very frustrating. Hope someone sees and could tell me what I'm doing wrong.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: COUNT DISTINCT & Progressbar Error

    Try naming the result set of your inner query:
    Code:
    SELECT COUNT (plaats) FROM (SELECT DISTINCT plaats FROM beslagdata) R
    What you name it isn't important, just that you name.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: COUNT DISTINCT & Progressbar Error

    Thanks for the tip

    Code:
    "SELECT COUNT (plaats) FROM (SELECT DISTINCT plaats FROM beslagdata) As blablabla"
    Why do you have to name it (as string) if it isn't needed anywhere, or is that a SQL-standard in the COUNT-case?


    What dit you mean with the R btw?


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  4. #4
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: COUNT DISTINCT & Progressbar Error

    Good practice...

    If you need to refer the column anywhere in your code, it's better to have a name that you know instead of a name that was automatically generated by SQL.

    The R question i can't answer...

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: COUNT DISTINCT & Progressbar Error

    It's not a string. It's an identifier, like a table name or column name. It has nothing to do with the COUNT function. It assigns a name to the result set of the inner query so it can be treated like a table, which it kinda is. In this case you don't need to use the name so, if it was supported, you could simply omit it but if you were to join that result set with another result set, table or view then you might well need to be able to refer to it to distinguish its columns from those from elsewhere with the same name. Why exactly the decision was made to require I don't know.

    I just used R for Result.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: COUNT DISTINCT & Progressbar Error

    Aha. Thank you both for the clear answer.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

Posting Permissions

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



Click Here to Expand Forum to Full Width