Guest_imported
New member
- Jan 1, 1970
- 0
I want this to be a matrix at the end. It is
very limiting right now.
Any suggestions please help it should function and
you can view the end required result as is.
/*
CREATE TABLE #users (UID int, uname varchar(20))
insert #users values(1, 'john')
insert #users values(2, 'mary')
insert #users values(3, 'frank')
CREATE TABLE #events (EID int PRIMARY KEY IDENTITY(1,1) NOT NULL,
UID int, sdesc varchar(50), sdate datetime)
insert #events values(1, 'email to client', '11/4/2001 8:30:00:00')
insert #events values(1, 'allow for dups', '11/4/2001 8:00:00:00')
insert #events values(1, 'went to client', '11/4/2001 11:00:00:00')
insert #events values(1, 'called client', '11/4/2001 13:00:00:00')
insert #events values(2, 'email to someone', '11/4/2001 9:00:00:00')
insert #events values(2, 'called someone', '11/4/2001 11:00:00:00')
insert #events values(2, 'do something', '11/4/2001 14:00:00:00')
insert #events values(3, 'went walking', '11/4/2001 8:00:00:00')
insert #events values(3, 'ate lunch', '11/4/2001 9:00:00:00')
CREATE TABLE #dayview (id int identity(1,1), sdate datetime)-- holds all possible time values
select * from #users
select * from #events
select * from #dayview
delete from #events
delete from #dayview
*/
--DECLARE ALL VARS
DECLARE @stime smalldatetime --office start date time
DECLARE @etime smalldatetime --office end time
DECLARE @timeh smalldatetime --variable
DECLARE @inc int --office increment
DECLARE @today smalldatetime --today
DECLARE @maxcol int --maximum headers
SET @stime= '11/4/2001 8:00:00:00'
SET @etime= '11/4/2001 17:00:00:00'
SET @inc=30
SET @today = '11/4/2001'
--SET TIME COLUMN
delete from #dayview
while @stime <= @etime
begin
insert into #dayview values (@stime)
set @stime = dateadd(mi, @inc ,@stime)
end
/*
--SET HEADER
--this is where I was going to increment the
--users table and then return the column headings
--something like select
*/
--CROSS TAB OF EVENTS
--this needs to be dynamic based on how many
--rows are in the users table
--not quite sure how to do this yet
SELECT convert(varchar(20),a.sdate, 108),
MIN( CASE b.UID WHEN 1 THEN b.sdesc END ),
MIN( CASE b.UID WHEN 2 THEN b.sdesc END ),
MIN( CASE b.UID WHEN 3 THEN b.sdesc END )
FROM #dayview a
LEFT JOIN #events b ON a.sdate=b.sdate
GROUP BY a.sdate
ORDER BY a.sdate
very limiting right now.
Any suggestions please help it should function and
you can view the end required result as is.
/*
CREATE TABLE #users (UID int, uname varchar(20))
insert #users values(1, 'john')
insert #users values(2, 'mary')
insert #users values(3, 'frank')
CREATE TABLE #events (EID int PRIMARY KEY IDENTITY(1,1) NOT NULL,
UID int, sdesc varchar(50), sdate datetime)
insert #events values(1, 'email to client', '11/4/2001 8:30:00:00')
insert #events values(1, 'allow for dups', '11/4/2001 8:00:00:00')
insert #events values(1, 'went to client', '11/4/2001 11:00:00:00')
insert #events values(1, 'called client', '11/4/2001 13:00:00:00')
insert #events values(2, 'email to someone', '11/4/2001 9:00:00:00')
insert #events values(2, 'called someone', '11/4/2001 11:00:00:00')
insert #events values(2, 'do something', '11/4/2001 14:00:00:00')
insert #events values(3, 'went walking', '11/4/2001 8:00:00:00')
insert #events values(3, 'ate lunch', '11/4/2001 9:00:00:00')
CREATE TABLE #dayview (id int identity(1,1), sdate datetime)-- holds all possible time values
select * from #users
select * from #events
select * from #dayview
delete from #events
delete from #dayview
*/
--DECLARE ALL VARS
DECLARE @stime smalldatetime --office start date time
DECLARE @etime smalldatetime --office end time
DECLARE @timeh smalldatetime --variable
DECLARE @inc int --office increment
DECLARE @today smalldatetime --today
DECLARE @maxcol int --maximum headers
SET @stime= '11/4/2001 8:00:00:00'
SET @etime= '11/4/2001 17:00:00:00'
SET @inc=30
SET @today = '11/4/2001'
--SET TIME COLUMN
delete from #dayview
while @stime <= @etime
begin
insert into #dayview values (@stime)
set @stime = dateadd(mi, @inc ,@stime)
end
/*
--SET HEADER
--this is where I was going to increment the
--users table and then return the column headings
--something like select
*/
--CROSS TAB OF EVENTS
--this needs to be dynamic based on how many
--rows are in the users table
--not quite sure how to do this yet
SELECT convert(varchar(20),a.sdate, 108),
MIN( CASE b.UID WHEN 1 THEN b.sdesc END ),
MIN( CASE b.UID WHEN 2 THEN b.sdesc END ),
MIN( CASE b.UID WHEN 3 THEN b.sdesc END )
FROM #dayview a
LEFT JOIN #events b ON a.sdate=b.sdate
GROUP BY a.sdate
ORDER BY a.sdate