• Last week I came up with this option. I haven't made performace tests. Maybe you could help me with that.

    DECLARE @test-2TABLE(

    myintint)

    INSERT INTO @test-2 VALUES(1),(2),(3),(4),(5),(6),(7),(8),(9);

    WITH CTE AS(

    SELECT myint,

    NTILE( 2) OVER( ORDER BY myint) tile

    FROM @test-2

    )

    SELECT CASE WHEN SUM( CASE WHEN tile = 1 THEN 1 END) = SUM( CASE WHEN tile = 2 THEN 1 END)

    THEN (MAX( CASE WHEN tile = 1 THEN myint END) + MIN( CASE WHEN tile = 2 THEN myint END))/2.0

    ELSE MAX( CASE WHEN tile = 1 THEN myint END) END

    FROM CTE

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2