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).

enter image description here

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

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -