G
Guest
I've one APPEND query, but I use another 'SELECT' query for selecting
records to be inserted... Following is the query...
PARAMETERS p_MonthLastDate DateTime;
INSERT INTO EmpInctStats
(Emp_ID,Total_Contribution,Sta_ID,Dis_ID,Trn_Date,Trn_Year,Trn_Month)
SELECT DISTINCT p.Emp_ID, (SELECT TOP 1 ECont.Total_Contribution FROM
EmpIncrStats ECont
WHERE ECont.Emp_ID=p.Emp_ID
AND ECont.Trn_Date<p_MonthLastDate
ORDER BY ECont.Trn_Date DESC) AS Total_Contribution, 1, 3, p_MonthLastDate,
YEAR(p_MonthLastDate), MONTH(p_MonthLastDate)
FROM EmpIncrStats AS p
WHERE p.Emp_ID NOT IN
(SELECT p1.Emp_ID FROM EmpIncrStats p1
WHERE p1.Trn_Date=p_MonthLastDate)
ORDER BY p.Emp_ID;
But the query isn't working... my machine stops responding after a couple of
minutes...
On the same data imported into SQL Server 2000 and T-SQL version of the same
query works fine and executes within 2 seconds...
Can anybody help me with this?
records to be inserted... Following is the query...
PARAMETERS p_MonthLastDate DateTime;
INSERT INTO EmpInctStats
(Emp_ID,Total_Contribution,Sta_ID,Dis_ID,Trn_Date,Trn_Year,Trn_Month)
SELECT DISTINCT p.Emp_ID, (SELECT TOP 1 ECont.Total_Contribution FROM
EmpIncrStats ECont
WHERE ECont.Emp_ID=p.Emp_ID
AND ECont.Trn_Date<p_MonthLastDate
ORDER BY ECont.Trn_Date DESC) AS Total_Contribution, 1, 3, p_MonthLastDate,
YEAR(p_MonthLastDate), MONTH(p_MonthLastDate)
FROM EmpIncrStats AS p
WHERE p.Emp_ID NOT IN
(SELECT p1.Emp_ID FROM EmpIncrStats p1
WHERE p1.Trn_Date=p_MonthLastDate)
ORDER BY p.Emp_ID;
But the query isn't working... my machine stops responding after a couple of
minutes...
On the same data imported into SQL Server 2000 and T-SQL version of the same
query works fine and executes within 2 seconds...
Can anybody help me with this?