Tema: Re: MSSQL : Kaip uzpildyti skyles
Autorius: Sabotage
Data: 2010-12-24 13:52:21
Jei nori be ciklo pabandyk ir prisitaikyk sau toki varianta:

Lentele:
table1
hour                                     num
2010-12-22 10:00:00.000     4
2010-12-22 11:00:00.000     NULL
2010-12-22 12:00:00.000     NULL
2010-12-22 13:00:00.000     7
2010-12-22 14:00:00.000     9
2010-12-22 15:00:00.000     NULL
2010-12-22 16:00:00.000     5

with mytable (hour, num, diff) as

(

select t1.hour, num = isnull(t1.num,t2.num), diff = datediff(hh, t2.hour, 
t1.hour)

from dbo.table1 t1

left join table1 t2

on t1.hour >= t2.hour

where t2.num is not null

)

select mt1.hour, mt1.num

from mytable mt1 join

(select hour, diff = min(diff) from mytable

group by hour) mt2

on mt1.hour = mt2.hour and mt1.diff = mt2.diff


"bala nemate" <bala.nemate@gmail.com> wrote in message 
news:ge436weas4l1$.x17s1w68nem8$.dlg@40tude.net...
> nu va, pagaliau prie kompo.
>
> nu matau, nieko naujo - while. maniau įmanoma be ciklo apseiti.
>
> škiasi, laiką valandom suskirstyti ne problema, tam funkcija turiu
> pasidaręs - sušėri periodo pradžios ir galo laikus, o ji sugeneruoja
> valandų įrašus. paskui prie rezultato left joininu reikiamus atvaizduoti
> parametrus.
>
> tai ir gauni - valandines eilutes, jei tuo metu yra Value suvestas - jį ir
> turiu, jei nėra - null'as sėdi.
>
> ok, dėkui už pamastymus, einu ciklų apsirašinėti :)
>
> -- 
> bn/mj
> skype : bala.nemate
> "The blues ain't about making yourself feel better.
> it's about making other people feel worse."
> -- Bleeding Gums Murphy