| Author |
Topic |
|
qalo
Starting Member
3 Posts |
Posted - 2006-10-31 : 12:39:42
|
| greetings all,i'm trying to crosstab or pivot this data with the following columns eg, date, datetime, eventype, eventid20061030, 2006-10-30 08:37:35, IN, 2034262420061030, 2006-10-30 08:37:51, OUT, 2034270320061030, 2006-10-30 08:38:13, IN, 2034282720061030, 2006-10-30 18:19:30, OUT, 20479241date, timein, timeout20061030, 08:37:35, 08:37:5120061030, 08:38:13, 18:19:30please help... |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-31 : 13:39:38
|
| [code]-- prepare test datadeclare @test table ([date] int, [datetime] datetime, eventype varchar(3), eventid int)insert @testselect 20061030, '2006-10-30 08:37:35', 'IN', 20342624 union allselect 20061030, '2006-10-30 08:37:51', 'OUT', 20342703 union allselect 20061030, '2006-10-30 08:38:13', 'IN', 20342827 union allselect 20061030, '2006-10-30 18:19:30', 'OUT', 20479241select * from @test-- do the workselect [in].[date], [in].[datetime] timein, [out].[datetime] timeoutfrom ( select t.[date], t.[datetime], (select min(q.eventid) from @test q where q.eventype = 'out' and q.eventid > t.eventid) eventid from @test t where t.eventype = 'in' ) [in]inner join @test [out] on [out].eventid = [in].eventidwhere [in].[datetime] <= [out].[datetime]order by 1, 2[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
qalo
Starting Member
3 Posts |
Posted - 2006-10-31 : 14:16:58
|
| thanks a million PETER, you're a star... |
 |
|
|
qalo
Starting Member
3 Posts |
Posted - 2006-11-01 : 10:26:36
|
| hi peter,i run that query with the real data & it's not 100% correct... |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-11-01 : 10:37:53
|
quote: Originally posted by qalo hi peter,i run that query with the real data & it's not 100% correct...
so what's wrong with it ? How many percent correct ? KH |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-01 : 10:52:02
|
| 99.453434 percent?Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|