|
-
Jul 29th, 2009, 02:41 AM
#1
Thread Starter
PowerPoster
[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.
-
Jul 29th, 2009, 02:47 AM
#2
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.
-
Jul 29th, 2009, 04:23 AM
#3
Thread Starter
PowerPoster
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?
-
Jul 29th, 2009, 04:29 AM
#4
-
Jul 29th, 2009, 04:35 AM
#5
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.
-
Jul 29th, 2009, 04:58 AM
#6
Thread Starter
PowerPoster
Re: COUNT DISTINCT & Progressbar Error
Aha. Thank you both for the clear answer.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|