SQLSTATE 42000 (Error 102) Incorrect syntax near 'ltv'

I'm new to SQL Server Agent and set up a job to run a query string that runs successfully in the query window.

It is a Transact-SQL script (T-SQL) type.

Delete from lookuptablevalues ltv
where ltv.keyvalue in
select distinct(si.value_ci) collate Latin1_General_CI_AS keyvalue
from recipientlists rl, recipientstringvalues rsv, rv_stringindex si, lookuptablevalues ltv,
recipientdatevalues rdv
    rsv.recipientid = rl.recipientid
and rl.recipientid = rdv.recipientid
and rsv.fieldid = 1462
and rl.listid=5773
and si.id = rsv.valueid
and ltv.lookupid=193
and ltv.keyvalue = si.value_ci collate Latin1_General_CS_AS
and rdv.value < getdate()-7

Open in new window

Can someone kindly educate to as to what is wrong?  Thanks in advance.
Who is Participating?
Jim Dettman (Microsoft MVP/ EE MVE)Connect With a Mentor PresidentCommented:
This doesn't look right:

Delete from lookuptablevalues ltv
where ltv.keyvalue in

Should be:

Delete from ltv
where ltv.keyvalue in

 Not sure how you get away with it in the query window...

kkbenjAuthor Commented:
The table name is lookuptablevalues, ltv being the abbreviation.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.