my data on database
account,number,value,counter
xxxx , 1 , 10000,1
null , null , 500000, 2
null , null , 10000 , 3
can sql query do result something like this :
account,number,value,counter
xxxx , 1 , 10000 ,1
xxxx , 1 , 500000 , 2
xxxx , 1 , 10000 , 3
can anyone help me. thanks
dennisc
September 16, 2015, 1:44am
2
let me try to understand it correctly, you trying to replace null in account column with xxxx and any null in number column to be 1?
yes thats true, but without update query,
account,number,value,counter
xxxx , 1 , 10000,1
null , null , 500000, 2
null , null , 10000 , 3
yyyy, 5 ,400000, 4
null , null , 50000 , 5
result something like this :
account,number,value,counter
xxxx , 1 , 10000 ,1
xxxx , 1 , 500000 , 2
xxxx , 1 , 10000 , 3
yyyy, 5 ,400000, 4
yyyy, 5 , 50000 , 5
khtan
September 16, 2015, 2:07am
4
SELECT account = coalesce(d.account, p.account),
number,
value,
counter
FROM data d
OUTER APPLY (
SELECT TOP 1 x.account
FROM data x
WHERE x.counter < d.counter
AND x.account IS NOT NULL
ORDER BY x.counter DESC
) p
@khtan thank you, your query working well (mssql), but if i try run on interactive sql sybase there is an error "incorrect syntax near 'OUTER' ",
khtan
September 16, 2015, 6:45am
6
I am not familiar with Sybase and SQLTeam.com is on MS SQL Server, For Sybase, try posting at a Sybase forum.