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 |
|
sandhyakalsotra
Starting Member
22 Posts |
Posted - 2010-06-09 : 12:53:49
|
| hi,i am using sql in billing of electricity consumers. My problem is that i need to make a querry to add the load consumption in a particular area. I used the statementSELECT SUM (loadsubstation) FROM dboloadbut the querry returns an error because the load is in KW as well as HP. please let me know how to modify this querry. |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-06-09 : 13:39:15
|
| What is the error? What datatype is the loadsubstation field? |
 |
|
|
sandhyakalsotra
Starting Member
22 Posts |
Posted - 2010-06-09 : 14:41:47
|
| datatype is int. actually want to querry in a way that the different units( HP and KW) are converted into one similar type i.e. KW before the SUM aggregate function executes.sandhya |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-06-09 : 14:46:11
|
| Yes. I understand that. But how do you know if its in KW or HP if the field is just int. Is there some other field that holds this? |
 |
|
|
GhantaBro
Posting Yak Master
215 Posts |
Posted - 2010-06-09 : 14:46:44
|
quote: Originally posted by sandhyakalsotra datatype is int. actually want to querry in a way that the different units( HP and KW) are converted into one similar type i.e. KW before the SUM aggregate function executes.sandhya
Need to convert HP to KW or vice-versa first... check online for the conversion unit and then use this new converted field in either in KW or HP to do the sum... yeah you should have another field that would say which records have HP values while which one has KW values... |
 |
|
|
sandhyakalsotra
Starting Member
22 Posts |
Posted - 2010-06-09 : 14:50:09
|
| yes there is another field that holds the information whether the data in the first field is in KW or HPsandhya |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-06-09 : 14:52:45
|
Use likeSELECT SUM (CASE WHEN someotherfield = 'KW' then loadsubstation ELSE loadsubstation * 0.745699 END) as ValueInKW FROM dboload |
 |
|
|
sandhyakalsotra
Starting Member
22 Posts |
Posted - 2010-06-09 : 14:58:00
|
| Thanx a lotz. I think that will solve the querry...sandhya |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-06-09 : 14:58:47
|
Np. Let us know if it doesn't |
 |
|
|
sandhyakalsotra
Starting Member
22 Posts |
Posted - 2010-06-09 : 15:38:40
|
| sure vijay, this forum is wonderful for beginners.sandhya |
 |
|
|
|
|
|