Solved

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

Posted on 2012-03-23
2
1,242 Views
Last Modified: 2012-06-21
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
where
    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.
0
Comment
Question by:kkbenj
2 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 37758822
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...

Jim.
0
 

Author Comment

by:kkbenj
ID: 37759050
The table name is lookuptablevalues, ltv being the abbreviation.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question