sql server 2008 - SQL Views - Modify Returned Result -


i'm little stuck here. i'm trying modify returned view based on condition. i'm green on sql , having bit of difficultly returned result. heres partial component of view wrote:

with (  select   row_number() on (partition fkidcontract,fkidtemplateitem order bstdactive desc, dtdateplanned asc) rank,   tblworkitems.fkidcontract contractno,   .... tblworkitems   fkidtemplateitem in                     (2895,2905,2915,2907,2908,                      2909,3047,2930,2923,2969,                      2968,2919,2935,2936,2927,                      2970,2979) , ... ) select * rank = 1 

the return result similar following:

contractno| itemnumber |    planned   |  complete   001     |    100     |  01/01/1900  | 02/01/1900   001     |    101     |  03/04/1900  | 02/01/1901   001     |    102     |  03/06/1901  | 02/08/1900   002     |    100     |  01/03/1911  | 02/08/1913 

this gives me results expect, due nightmare crystal report need alter view slightly. want take returned result set , modify existing column value pulled same table , same contract relationship, following:

update set a.completed = ( select  r.completed                         mytable r                             inner join                                 on a.contractno = r.contractno a.itemnumber = 100 , r.itemnumber = 101                         ) 

what i'm trying modify "completed date" of 1 task , make complete date of task if both share same contractno field value.

i'm not sure itemnumber relationships between , r (perhaps testing...), seems don't want update anything, want use different value under circumstances. so, maybe want change non-cte part of query like:

select a.contractno, a.itemnumber, a.planned,         coalesce(r.completed,a.completed) completed left outer join mytable r on a.contractno = r.contractno , a.itemnumber = 100 , r.itemnumber = 101  -- i'm not sure part a.rank = 1 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

html - Repeat image to extend header to fill screen -

javascript - Backbone.js getting target attribute -