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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Why does Group By mess up my data

Author  Topic 

JohnBGood
Starting Member

48 Posts

Posted - 2010-03-01 : 20:42:58
I just added a field called CellPadding to this query... prior to that it was working perfectly. After adding it, the query wont parse unless i include CellPadding field in the Group By... If i do that it messes up my data big time. Am I stuck??


select
start_ID as ID
,MemberValue
,start_parentID as ParentID
,sum(work) as PlannedWork
,Sum(Capacity) as Capacity
,10 as Number_of_Users
,1 as Number_of_Logins
,'http://www.google.com' as ResourseStatusLink
,'http://www.msn.com' as EPMUsageLink
,CellPadding

from cte
group by start_ID, MemberValue,start_parentID

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2010-03-01 : 21:07:29
No you are not stuck, it just appears you do not know what you are doing :)
What exactly are you expecting to happen? What value of 'CellPadding' are you expecting to see in your aggregate lines if you didn't group by it?
Go to Top of Page

JohnBGood
Starting Member

48 Posts

Posted - 2010-03-01 : 21:17:23
Thanks for that! I'm a noobe for sure.

The cell padding is a integer. when i add it to the group by, i return many additional rows. I don't want the member value to repeat - which it does when I add the CellPadding to the groupBy. Does that Help??
Go to Top of Page

JohnBGood
Starting Member

48 Posts

Posted - 2010-03-01 : 22:17:44
Still there? I'll owe you big if you can help. Case of beer?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-02 : 09:05:47
quote:
Originally posted by JohnBGood

Still there? I'll owe you big if you can help. Case of beer?


can you provide some supplimentary data and show what output you're expecting out of it?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2010-03-02 : 09:17:38
When you introduce a new value all your aggregates are then subdivided again, grouped by all the values. If it's a constant you're ok. If it lives in the table you cannot do it without changing the output.
Provide some data & expected output and you will start to see why it cannot work. It does make sense.
Go to Top of Page

JohnBGood
Starting Member

48 Posts

Posted - 2010-03-02 : 21:36:46
After banging my head.. i finally got it. Thank you very much for your help!
Go to Top of Page
   

- Advertisement -