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 |
|
Mmats
Starting Member
47 Posts |
Posted - 2005-04-07 : 14:14:38
|
| I want to do something like the following:Select sum(q5)/ count(q5) as [q5 overall mean], sum(q5)/ count(q5) as [q5_temp]Is there a way to do the calculation only once, since its the same? |
|
|
rfrancisco
Yak Posting Veteran
95 Posts |
Posted - 2005-04-07 : 14:31:04
|
| I don't think there's a way to do this, unless I'm mistaken. |
 |
|
|
PW
Yak Posting Veteran
95 Posts |
Posted - 2005-04-07 : 14:55:56
|
| Have you actually run a showplan on this to verify that Sql Server performs the calculation twice ?I would expect to see query plan steps of "Stream Aggregate/Aggregate" and "Compute Scalar", where the 1st performs the aggregate calculation, and the 2nd simply assigns the already computed value to the 2nd column. |
 |
|
|
Kaleem021
Starting Member
26 Posts |
Posted - 2005-04-08 : 01:04:39
|
Try this if [q5 overall mean] remains same for every record of your select query. Declare @q5 As FloatSet @q5 = (Select sum(q5)/ cast(count(q5) as Float) from <Your Table Name>)SELECT @q5 as [q5 overall mean], @q5 as q5_temp from <Your Table Name> *****************************************************************************Myth BreakerKaleem021@hotmail.comDoing Nothing Is Very Hard To Do, You Never Know When You Are Finished. |
 |
|
|
|
|
|