sql - Sort result when using ROW_NUMBER() -
this follow-up this question asked yesterday.
did not know if should expand original question, decided start new 1 (bear me...)
my select
@ moment:
select * ( select a.guid_column1, b.guidid_column1, c.date_column1, d.guid_column1 row_number() on (partition a.guid_column1, b.guid_column1 order c.date_column1 desc) rn ... -- joins , stuff here .... ) t t.rn = 1
i (expected) result this:
a.guid_column1 b.guid_column1 c.date_column1 d.guid_column1 ------------------------------------------------------------------- a1 b1 07/08/2013 someuniqueid a2 b2 05/06/2012 someuniqueid
the tricky part sort result dateadd
, order dateadd(month, a.float_column, c.date_column1) asc
a.float_column
of course not same (and in fact entered user later on).
is there way accomplish in sql (i'm using sql server 2005)
below query calculate new date in select-clause.
if a.float_column
null
nothing added original date.
select dateadd(month, isnull(t.float_column,0), t.date_column1) newdate , * ( select a.guid_column1, b.guidid_column1, c.date_column1, d.guid_column1, a.float_column row_number() on (partition a.guid_column1, b.guid_column1 order c.date_column1 desc) rn ... -- joins , stuff here .... ) t t.rn = 1 order newdate asc
Comments
Post a Comment