Hello guys,
I have a query that works fine but it it really really slow. Could someone help to make this operation a little bit more viable.
The table1 is identical and more up to date than table2, so it consists to check if a date exists in the table2 and if the date doesn't exist table2, it needs to update this table from table1.
IF EXISTS (
SELECT *
FROM table1
WHERE table1.sc = 7 and table1.code = 101 and table1.date not in (
SELECT table2.date
FROM table2
WHERE table2.se = 7 and table2.code = 101 ))
INSERT INTO table2 (CODE, QQ, QS, DATE, VALUE, SC)
SELECT CODE, QQ, QS, DATE, VALUE, SC
FROM table1
WHERE table1.sc = 7 and table1.code = @Code
and table1.date not in (
SELECT table2.date
FROM table2
WHERE table2.sc = 7 and table2.code = @Code)
ELSE
print 'not insert'
I have 2000 rows and it is not too much but 1 operation (every Loop) pro second it is a little slow :O
any suggestions?
Ina
I have a query that works fine but it it really really slow. Could someone help to make this operation a little bit more viable.
The table1 is identical and more up to date than table2, so it consists to check if a date exists in the table2 and if the date doesn't exist table2, it needs to update this table from table1.
IF EXISTS (
SELECT *
FROM table1
WHERE table1.sc = 7 and table1.code = 101 and table1.date not in (
SELECT table2.date
FROM table2
WHERE table2.se = 7 and table2.code = 101 ))
INSERT INTO table2 (CODE, QQ, QS, DATE, VALUE, SC)
SELECT CODE, QQ, QS, DATE, VALUE, SC
FROM table1
WHERE table1.sc = 7 and table1.code = @Code
and table1.date not in (
SELECT table2.date
FROM table2
WHERE table2.sc = 7 and table2.code = @Code)
ELSE
print 'not insert'
I have 2000 rows and it is not too much but 1 operation (every Loop) pro second it is a little slow :O
any suggestions?
Ina