Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, I am getting an error:
Msg 102, Level 15, State 1, Line 28 Incorrect syntax near '.'.

This seems to be occurring at statement: SET fa.Focus_FarmExceptional = 'Y'

I can't seem to see it. I've been looking at this for a while and to me, it appears like it should work just fine but is not. Any help greatly appreciated.

SQL
DECLARE @FarmList NVARCHAR(MAX)
DECLARE @CommercialList NVARCHAR(MAX)
DECLARE @PersonalList NVARCHAR(MAX)
DECLARE @tbl_Farm TABLE(ID VARCHAR(8))
DECLARE @tbl_Personal TABLE(ID VARCHAR(8))
DECLARE @tbl_Commercial TABLE(ID VARCHAR(8))

BEGIN
UPDATE  [DCT-Dev_ExampleData].[dbo].[tbl_FocusAgents] 
--reset/default all rows 
SET Focus_FarmExceptional = 'N',
Focus_CommercialExceptional = 'N',
Focus_PersonalExceptional = 'N'
END
--FARM


--populate Farm list for tables
SET @FarmList = '0008144,0007844,0007854,000321,000123'
INSERT INTO @tbl_Farm (ID) 
SELECT * FROM dbo.Split(@FarmList,',')
SELECT * FROM @tbl_Farm

BEGIN
UPDATE  [DCT-Dev_ExampleData].[dbo].[tbl_FocusAgents] 
--update Farm
SELECT * FROM @tbl_Farm 
SELECT * from  dbo.tbl_FocusAgents fa
INNER JOIN @tbl_Farm f on f.ID = fa.Focus_FocusAgentCd
SET fa.Focus_FarmExceptional = 'Y'
WHERE fa.Focus_FocusAgentCd IN (SELECT ID FROM @tbl_Farm)
END
Posted
Comments
You are selecting inside the Update statement. I am not sure whether it is supported or not. Research on this.

Not sure what you are trying to do here

SQL
SET @FarmList = '0008144,0007844,0007854,000321,000123';
INSERT INTO @tbl_Farm (ID)
SELECT * FROM dbo.Split(@FarmList, ',')
SELECT * FROM @tbl_Farm


but it is a bad idea to try and do a insert records into the same table you getting the data from.

Also the following code is not the standard way run an update query



UPDATE  [DCT-Dev_ExampleData].[dbo].[tbl_FocusAgents] 
--update Farm
SELECT * FROM @tbl_Farm 
SELECT * from  dbo.tbl_FocusAgents fa
INNER JOIN @tbl_Farm f on f.ID = fa.Focus_FocusAgentCd
SET fa.Focus_FarmExceptional = 'Y'
WHERE fa.Focus_FocusAgentCd IN (SELECT ID FROM @tbl_Farm)


it should be somthing more like

UPDATE [tbl_FocusAgents]
SET fa.Focus_FarmExceptional = 'Y'
WHERE fa.Focus_FocusAgentCd IN (SELECT ID FROM @tbl_Farm)


and add any other select statements you need as part of the where clause.
 
Share this answer
 
You have far more in your update statement than you actually need. The double selects (if they are even supported) and the where clause are unnecessary. This should do what you're trying to accomplish:

SQL
UPDATE fa
SET fa.Focus_FarmExceptional = 'Y'
FROM        dbo.tbl_FocusAgents fa
INNER JOIN  @tbl_Farm f ON f.ID = fa.Focus_FocusAgentCd


All we're doing here is building a from clause to select only the records we want to update, then updating the aliased table 'fa' rather than selecting from it. Rather simple once you understand how to do it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900