Hi
i have one database table Table1.which contains almost 20000000 recordes.
record to this table are inserted through storedprocedure . storedprocedure takes parameter as
"value",
Beginningdate,
Endate .
which will insert one record for each day between Beginning date and EndDate.
Before inserting record i check is record exsist for date,if exsist i will update value otherwise insert new record.
so in there is 3000 days diff between Beginning date And EndDate its taking so much time so plz help me.
Here is code of sp
BEGIN
WHILE @BeginningDate <= @EndDate
BEGIN --- Start While LOOP
IF NOT EXISTS
(
SELECT * FROM Table1 WITH (NOLOCK)
WHERE BeginningDate = @BeginningDate
)
BEGIN --- Start Insert Sql Querry
INSERT INTO Table1
(
Val,
BeginningDate,
EndDate
)
Values
(
@Val,
@BeginningDate,
@BeginningDate
)
END --- Endof Insert Sql Querry
ELSE
BEGIN --- Start Update Sql Querry
UPDATE Table1 WITH (ROWLOCK)
SET
Val=@Val
WHERE
BeginningDate = @BeginningDate
END --- Endof Update Sql Querry
SET @BeginningDate = @BeginningDate + 1;
END --- Endof While LOOP
END
i have one database table Table1.which contains almost 20000000 recordes.
record to this table are inserted through storedprocedure . storedprocedure takes parameter as
"value",
Beginningdate,
Endate .
which will insert one record for each day between Beginning date and EndDate.
Before inserting record i check is record exsist for date,if exsist i will update value otherwise insert new record.
so in there is 3000 days diff between Beginning date And EndDate its taking so much time so plz help me.
Here is code of sp
BEGIN
WHILE @BeginningDate <= @EndDate
BEGIN --- Start While LOOP
IF NOT EXISTS
(
SELECT * FROM Table1 WITH (NOLOCK)
WHERE BeginningDate = @BeginningDate
)
BEGIN --- Start Insert Sql Querry
INSERT INTO Table1
(
Val,
BeginningDate,
EndDate
)
Values
(
@Val,
@BeginningDate,
@BeginningDate
)
END --- Endof Insert Sql Querry
ELSE
BEGIN --- Start Update Sql Querry
UPDATE Table1 WITH (ROWLOCK)
SET
Val=@Val
WHERE
BeginningDate = @BeginningDate
END --- Endof Update Sql Querry
SET @BeginningDate = @BeginningDate + 1;
END --- Endof While LOOP
END
Comment