January 18, 2011 at 8:23 am
I have a situation where I need to calculate the avg sal only when I have a recent value.
i.e,
table:
id reportingperiod sal
1 jan 2000
1 aug 2200
2 jan 2000
2 aug 0
I want the result to be:
id avg(sal)
1 2100
2 0
I tried alot using case statements but I think I am missing some thing there..
Please help me...
Thanks.
January 18, 2011 at 8:28 am
is reportingperiod actually a char data type or is it a date data type?
January 18, 2011 at 8:32 am
Its a character data type
January 18, 2011 at 8:42 am
with a datetime it would be easy to work out what the most recent value, with characer field it would be more difficult do you have any columns that would define what a recent value is?
January 18, 2011 at 8:51 am
NO 🙁
I donot have any other column which defines the reportingperiod..
January 18, 2011 at 9:59 am
Is there any specific reason for starting two threads with the identical issue within one hour?
(http://www.sqlservercentral.com/Forums/FindPost1049494.aspx) :angry:
January 18, 2011 at 10:22 am
No further replies to this thread please.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply