Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
lamiajoyee
Starting Member
15 Posts |
Posted - 2012-01-15 : 10:06:52
|
| hello when we read data from sql we use reader["columnname"].my problem is that when my query is like this "select sum(columnname) from table" what will i specify in the reader["columnname"] field?please specify |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-15 : 10:18:19
|
you should give it an alias like belowselect sum(columnname) as colsum from table and then use reader["colsum"]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-01-15 : 10:18:44
|
| You will either need to initialize a variable and then aggregate as you iterate through each row in the reader, ORA MUCH better option, let SQL do the summation for you. Change your query string to something like "select sum(columnname) AS SUMCOLUMN from yourTable". If you are only trying to get the sum, you could even use ExecuteScalar in that case.Edit: misread the question. OP is asking for aliasing, correction in red.. |
 |
|
|
lamiajoyee
Starting Member
15 Posts |
Posted - 2012-01-15 : 10:44:37
|
| thank you all |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-15 : 11:41:33
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|