We have an asp page that displays different tables for different users. The table structures and data are stored in our SQL database. The tables are stored into our sql database. The table is as follows: TemplateID, Cols, Rows, CellData. So if we have a templateID of 97 then that may be a table with three rows and two columns, and the data for those cells is stored in this table as well. The TemplateID however is not unique.
here's an example of the table:
templateID COLS ROWS DATA
3 1 1 celldata
3 2 1 celldata
3 2 2 celldata
4 1 1
4 2 1
4 3 1
4 4 1
So, table template three would have two cols and two rows, and the cell data. Template 4 would have 4 colms and one row and the cell data.
So we haven't yet determined a key(which would likely be a composite of the first three fields)
We pass in a HUGE string that is delimited by ASCII characters, and it contains the rows and colms. We want to run an update on the celldata depending on what the new data that's passed in is. Here is our query...It takes FOREVER and pounds our system. Can anyone think of a better way to arrange it? (I don't really expect anyone to re-write it, just some hints would be very helpful)
CREATE PROCEDURE sp_ActivityUpdateDatabaseStreamline
(
@template_id int,
@rows int,
@columns int,
@celldata_string varchar(8000)
)
AS
SET NOCOUNT OFF
DECLARE @y int
DECLARE @x int
DECLARE @temp varchar(50)
Set @y = 1
Set @x = 1
WHILE CHARINDEX ('¿',@celldata_string) > 0
BEGIN
WHILE @x < (@columns + 1)
BEGIN
SELECT @temp = left(@celldata_string,CHARINDEX ('¿',@celldata_string)-1)
SELECT @celldata_string = right(rtrim(@celldata_string),rtrim(len(@celldata_string)) - CHARINDEX ('¿',@celldata_string))
UPDATE ActivityTemplateCellData
SET CellData = @temp
WHERE
TemplateID = @template_id
AND
RowNbr = @y
AND
ColumnNbr = @x
SET @x = @x + 1
END
SET @y = @y + 1
SET @x = 1
END
here's an example of the table:
templateID COLS ROWS DATA
3 1 1 celldata
3 2 1 celldata
3 2 2 celldata
4 1 1
4 2 1
4 3 1
4 4 1
So, table template three would have two cols and two rows, and the cell data. Template 4 would have 4 colms and one row and the cell data.
So we haven't yet determined a key(which would likely be a composite of the first three fields)
We pass in a HUGE string that is delimited by ASCII characters, and it contains the rows and colms. We want to run an update on the celldata depending on what the new data that's passed in is. Here is our query...It takes FOREVER and pounds our system. Can anyone think of a better way to arrange it? (I don't really expect anyone to re-write it, just some hints would be very helpful)
CREATE PROCEDURE sp_ActivityUpdateDatabaseStreamline
(
@template_id int,
@rows int,
@columns int,
@celldata_string varchar(8000)
)
AS
SET NOCOUNT OFF
DECLARE @y int
DECLARE @x int
DECLARE @temp varchar(50)
Set @y = 1
Set @x = 1
WHILE CHARINDEX ('¿',@celldata_string) > 0
BEGIN
WHILE @x < (@columns + 1)
BEGIN
SELECT @temp = left(@celldata_string,CHARINDEX ('¿',@celldata_string)-1)
SELECT @celldata_string = right(rtrim(@celldata_string),rtrim(len(@celldata_string)) - CHARINDEX ('¿',@celldata_string))
UPDATE ActivityTemplateCellData
SET CellData = @temp
WHERE
TemplateID = @template_id
AND
RowNbr = @y
AND
ColumnNbr = @x
SET @x = @x + 1
END
SET @y = @y + 1
SET @x = 1
END