Jump to content
Xtreme .Net Talk

Recommended Posts

  • Administrators
Posted

something like

SELECT rank, (cast (rank as float) * 100 / (select sum(rank) from tblpoll)) from tblpoll

 

without knowing the table structure for sure I can't be sure. However here is a similar idea using northwind's Employees table

select reportsto,(select sum(reportsto) from employees),
(cast (reportsto as float) * 100 / (select sum(reportsto) from employees)) 
from employees

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Dear guy,I have a new problem:

http://shahabedeen.europe.webmatrixhosting.net/pic/persentile05.gif

As u can see the float point is not beautiful enough,How can I reduce the float points to 2 number? :rolleyes: :D

Posted

ANOTHER PROBLEM:

 

"SELECT RName,Rank,"+

"(cast (rank as float) * 100/"+

"(SELECT CAST(sum(rank) AS FLOAT )from tblpoll AS NUMERIC(3,2) )"+

" as Percentage FROM tblPoll)";

 

//SELECT CAST(rank/(select cast(sum(rank)

//as float) from tblpoll) AS NUMERIC(5,2)) as rank from tblpoll

 

error:

Line 1: Incorrect syntax near ','.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

 

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near ','.

 

Source Error:

 

 

Line 100:

Line 101: SqlDataReader myReader;

Line 102: myReader = myCommand.ExecuteReader();

Line 103:

Line 104: DataGrid1.DataSource = myReader;

 

 

Source File: d:\inetpub\wwwroot\projects\poll\pooluc.ascx.cs Line: 102

Posted (edited)
void GridBinder()
{		
string strCon = ConfigurationSettings.AppSettings["ConnStr"];
SqlConnection objConn = new SqlConnection(strCon);      						 
string mySelectQuery = "SELECT Rname,rank,CAST(rank/"+ "(select cast(sum(rank) as float) from tblpoll) AS NUMERIC(5,2)) as Percentage from tblpoll";
/*"SELECT RName,Rank,"+ "(cast (rank as float) * 100/"+ "(SELECT CAST(sum(rank) AS FLOAT )from tblpoll AS NUMERIC(3,2) )"+ "  as Percentage FROM tblPoll)";			*/
		
//SELECT CAST(rank/(select cast(sum(rank)
//as float) from tblpoll) AS NUMERIC(5,2)) as rank from tblpoll

SqlCommand myCommand = new SqlCommand(mySelectQuery,objConn);

objConn.Open();
		
SqlDataReader myReader;
myReader = myCommand.ExecuteReader();
		
DataGrid1.DataSource = myReader;
DataGrid1.DataBind();
}

Edited by PlausiblyDamp
Posted

Try this:

 

SELECT RNAME, RANK,

CAST(rank/(select cast(sum(rank) as float) from tblpoll) * 100 AS DECIMAL(5,2)) as Percentage from tblpoll

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...