As the title implies, I am getting the following error message with some SQL I'm trying to use. I'm using MS Management Studio 2008 with a link to a 2005 server.
What confuses me is that when I change the first line from a DELETE to a SELECT, the SQL works exactly as I would expect it to.
Just to be crystal clear, I'm talking about replacing line 1 with :
Background :
I have a table consisting of two fields, [AR_Analysis] (nvarchar(4)) and [AR_Range] (smallint). Each record is unique but neither field is. Valid values in [AR_Analysis] start with a '0' and are 4 characters long. I have the table populated currently with various matching pairs, but I have a new list of pairs within that list which should be deleted. To effect this I added the pairs to be deleted into the table but with a '1' as the first character of [AR_Analysis] but otherwise the same. I intend to clear away the original invalid items, as well as the new deletion items (starting with '1') with the above SQL. Let me see if I can make this easier with some example data :
Table = [AnalysisRange]
The valid data left after the process is complete should be :
The strange part, that completely confuses me, is that the results produced by what is essentially the same SQL when used as a SELECT query are exactly as I'd expect. When the DELETE query is attempted though, I get the message :
I have checked in the Books Online help system, but wasn't able to decipher an answer in it. Maybe I need to get more used to the terminology, but for now it's too obscure for me.
PS. Any advice as to alternative ways of approaching my main problem is welcomed (I'm sure I'm not using the best approach) but I'm mainly interested in the specific question as to why what I'm attempting is causing this response.
What confuses me is that when I change the first line from a DELETE to a SELECT, the SQL works exactly as I would expect it to.
Code:
DELETE FROM [DBManagement].[dbo].[AnalysisRange] AS [tAR] INNER JOIN [DBManagement].[dbo].[AnalysisRange] AS [tAR2] ON SUBSTRING([tAR].[AR_Analysis],2,3)=SUBSTRING([tAR2].[AR_Analysis],2,3) AND [tAR].[AR_Range]=[tAR2].[AR_Range] WHERE SUBSTRING([tAR2].[AR_Analysis],1,1)='1' GO
Code:
SELECT [tAR].*, [tAR2].*
I have a table consisting of two fields, [AR_Analysis] (nvarchar(4)) and [AR_Range] (smallint). Each record is unique but neither field is. Valid values in [AR_Analysis] start with a '0' and are 4 characters long. I have the table populated currently with various matching pairs, but I have a new list of pairs within that list which should be deleted. To effect this I added the pairs to be deleted into the table but with a '1' as the first character of [AR_Analysis] but otherwise the same. I intend to clear away the original invalid items, as well as the new deletion items (starting with '1') with the above SQL. Let me see if I can make this easier with some example data :
Table = [AnalysisRange]
Code:
[I][AR_Analysis] [AR_Range][/I] 0401 21 0401 22 0401 23 0420 20 0420 22 0420 24 1401 22 1420 24
Code:
[I][AR_Analysis] [AR_Range][/I] 0401 21 0401 23 0420 20 0420 22
Code:
Msg 156, Level 15, State 1, Line 2 Incorrect syntax near the keyword 'AS'.
PS. Any advice as to alternative ways of approaching my main problem is welcomed (I'm sure I'm not using the best approach) but I'm mainly interested in the specific question as to why what I'm attempting is causing this response.
Comment