Friday, 15 February 2013

TSQL Syntax, Replace Existing "Wrong Value" with previous "Correct Value" -



TSQL Syntax, Replace Existing "Wrong Value" with previous "Correct Value" -

i have application makes entry every hr in ms sql database. lastly entry on 12th feb 0 value , showing in weekly report.

what want take value previous count , come in filed instead of 0 value.

can offer advice on how because beyond tsql skills?

select * [dbo].[countdetails] [updatetime] < '2013-02.13' , [updatetime] > '2013-02.12' , ( datepart(hh,[updatetime])= '22' or datepart(hh,[updatetime])= '23' )

note: application supposed 0 count midnight on 12th feb happened , know why.

edit: there 5 ip addresses in total , 6 counters in total because 192.168.168.11 has 2 counters. 2111 2116 entire entry available counters @ 22:58 , 2117 2122 entire entry available counters @ 23:58. need replace 23:58 values corresponding value 22:58.

guessing here, update joins on ipaddress, counternumber, , datetime excluding fractional seconds, separated hr (do select part first safety):

update b set count = a.count -- select * dbo.countdetails bring together dbo.countdetails b on a.ipaddress = b.ipaddress , a.counternumber = b.counternumber , convert(varchar(20),b.updatetime,120) = convert(varchar(20),dateadd(hour,1,a.updatetime),120)

tsql

No comments:

Post a Comment