Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this code gives a exception saying that "incorrect syntax near the word DISTINCT"
what is wrong in this query?

private SqlConnection con;
private SqlCommand cmd;
private SqlDataReader dr;

openConnection();
string qry1 = "SELECT COUNT (V1) FROM votes GROUP BY DISTINCT V1";
cmd = new SqlCommand(qry1, con);

dr = cmd.ExecuteReader();
while (dr.Read())
{
 count = dr[0].ToString();
}
int ans= Convert.ToInt32(count);
MessageBox.Show(Convert.ToString(ans));

closeConnection();
Posted
Updated 4-Jul-11 7:32am
v2

SELECT COUNT (DISTINCT V1) FROM votes group by v1;

TRY THIS...
 
Share this answer
 
v2
change this:

string qry1 = "SELECT COUNT (V1) FROM votes GROUP BY DISTINCT V1";


with this:

string qry1 = "SELECT COUNT (V1) FROM votes GROUP BY V1";


hope this helps :)
 
Share this answer
 
TRY THIS

SELECT DISTINCT COUNT (V1) FROM votes GROUP BY V1
 
Share this answer
 
TRY THIS

SELECT DISTINCT COUNT (V1) FROM votes GROUP BY V1
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900