April 21, 2010 at 7:42 pm
i have a requirement to find median of two date column in a table.
Can anyone suggest how do i achieve it in sql query?
Thanks for any help
April 21, 2010 at 7:44 pm
keywestfl9 (4/21/2010)
i have a requirement to find median of two date column in a table.Can anyone suggest how do i achieve it in sql query?
Thanks for any help
What would be the business reason for needing this? And what have you tried so far?
---------------------------------------------------------
How best to post your question[/url]
How to post performance problems[/url]
Tally Table:What it is and how it replaces a loop[/url]
"stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."
April 21, 2010 at 9:00 pm
keywestfl9 (4/21/2010)
i have a requirement to find median of two date column in a table.Can anyone suggest how do i achieve it in sql query?
Thanks for any help
How's this?
DECLARE @Date1 datetime = '20080915',
@Date2 datetime = GetDate()
SELECT DateAdd(day, DateDiff(day, @Date1, @Date2)/2, @Date1)
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
April 21, 2010 at 9:24 pm
For 2 exactly - the median is the average of the 2 numbers.
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
April 21, 2010 at 9:53 pm
Matt Miller (#4) (4/21/2010)
For 2 exactly - the median is the average of the 2 numbers.
Well, keywestfl9 did say:
i have a requirement to find median of two date column in a table.
(emphasis mine)
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
April 22, 2010 at 7:03 am
WayneS (4/21/2010)
Matt Miller (#4) (4/21/2010)
For 2 exactly - the median is the average of the 2 numbers.Well, keywestfl9 did say:
i have a requirement to find median of two date column in a table.
(emphasis mine)
Correct! I was just clarifiyng what the math (i.e. the one you showed) actually represented. Was also hoping to emphasize ths is the only place the calculation is this simply.
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply