I'm trying to code a timesheet app for a project I'm doing, and for the best part of a month I've no progressed with a key part of the system. I need to be able to edit and add data into the app via a weekly view Mon-Sun. I have a SQL (server) pivot that can return the data I eneter daily, but since its using dynamic headers for the dates in the week, the gridview function to edit, will not work. I've tried binding data but this has the same issues, with the dates. I think I need to create a form that has text boxes to enter the data and update this way, but how can I populate such a form using the query I have ? I also need to be able to add new rows. I'm at the end of my tether with this and on the verge of abandoning the coding as its just stressing me out now.
Heres my SQL that displays the data exactly how I want:
ALTER PROCEDURE [dbo].[list_weekly_times]
as
DECLARE @offSetmon int, @fromdt datetime,@todt datetime,@offsetsun int, @COLName varchar (max)
, @SQL varchar (max), @fromdate as date, @todate as date, @offsetmonval as int, @offsetsunval as int
SELECT @offSetmon = 1
select @fromdt = GETDATE()
SELECT @offSetSun = 7
select @todt = GETDATE()
SELECT @fromdt = CONVERT(DATETIME, CONVERT(INT, @fromdt) - (DATEPART(WEEKDAY, @fromdt) - @offSetmon))
SELECT @todt = CONVERT(DATETIME, CONVERT(INT, @todt) - (DATEPART(WEEKDAY, @todt) - @offSetsun))
select @COLName = ''
, @SQL = ''
while @FromDt <= @ToDt
begin
if (@COLName = '')
begin
set @COLName = '[' + convert (varchar (10), @FromDt, 121) + ']'
end
else
begin
set @COLName = @COLName + ', [' + convert (varchar (10), @FromDt, 121) + ']'
end
set @FromDt = dateadd (d, 1, @FromDt)
end
print @COLName
select @SQL = 'select project_code, activity_code,' + @COLName +
' From (select project_code, activity_code, project_date, Project_time from timesheet) as P
pivot
( sum (Project_time)
for project_date in (' + @COLName + ')
) as pvt
order by project_code
'
print @SQL
exec (@SQL)
Just won't work with editing as pivots are designed for data display rather than data edit.
Maybe the pivot approach is wrong and another direction is needed.
Any help, tutorials, examples would help.