Aleks
asked on
sql syntax
I have the following sql to select a number of records. I get a total of 280
I now want to delete them so I tried
But i get this error
SELECT *
FROM Activities a
INNER JOIN Cases AS b ON a.CaseId = b.Id
INNER JOIN Atts AS d ON d.CaseId = b.Id
LEFT JOIN Users AS c ON a.responsible = c.UserId
INNER JOIN Users AS e ON b.AlienId = e.UserId
WHERE a.FirmId = 9
AND ( a.ActType = 'TASK'
OR a.ActType = 'DEADLINE'
)
AND a.Complete = '0'
AND a.DateInitiated < LEFT(DATEADD(DAY, 0, GETDATE()), 12)
AND b.Archived <> 1
AND c.UserId is null
ORDER BY c.MailStr ASC;
I now want to delete them so I tried
DELETE
FROM Activities a
INNER JOIN Cases AS b ON a.CaseId = b.Id
INNER JOIN Atts AS d ON d.CaseId = b.Id
LEFT JOIN Users AS c ON a.responsible = c.UserId
INNER JOIN Users AS e ON b.AlienId = e.UserId
WHERE a.FirmId = 9
AND ( a.ActType = 'TASK'
OR a.ActType = 'DEADLINE'
)
AND a.Complete = '0'
AND a.DateInitiated < LEFT(DATEADD(DAY, 0, GETDATE()), 12)
AND b.Archived <> 1
AND c.UserId is null
But i get this error
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'a'.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The delete was that of 89 records. But when I run the select again I get zero results :$
Is this correct ? the select returns more records because of the inner joins ?