sql server - T-SQL Update Null Values With Previous values (not necessarily immediately before) based on seat location, ID and Time -
i using mssms 2008 r on win7 machine.
i extremely new sql , still trying grasp fundamentals, different have used in past. bare me...
i having issues trying hands on data. here looks after munged heck out of (this small set).
i need search null values in mediaid col. (which straight forward enough).
once have found these values, need search (in time) same location , logid occurred right before null values' time-stamp , replace null correct mediaid.
i have solid understanding of problem , how approach (in languages) sql weird , giving me problems... took me forever data stage have no idea go here. have researched cte's , cursors still unsure how apply these methods.
btw sorry cannot post of code due nature of work, think enough info ponder.
you can use subquery update column previous value using code below:
update t set t.mediaid = ( select top 1 mediaid yourtable s s.logid = t.logid , s.location = t.location , s.time < t.time order [time] desc) yourtable t t.mediaid null 
Comments
Post a Comment