Share via

How to Fix SQL Syntax Error in Code

Carlton Patterson 761 Reputation points
2023-01-23T10:44:55.13+00:00

Hello Community,

I'm getting the following error

Incorrect syntax near the keyword 'FROM'.

When I execute the following query:

WITH cte AS ( SELECT accountid FROM STRING_SPLIT(ts_montaguoffice, ';') as ts_montaguofficeonly 
  FROM core.account ) SELECT accountid, ts_montaguofficeonly 
  FROM cte CROSS APPLY (SELECT value FROM STRING_SPLIT(ts_montaguofficeonly, ';')) as split

I know its something simple, but could someone let me know how to resolve this error?

Thanks

SQL Server | Other
0 comments No comments

Answer accepted by question author

  1. Viorel 126.9K Reputation points
    2023-01-23T11:00:00.6233333+00:00

    This works for me:

    SELECT accountid, t.value as ts_montaguofficeonly
    FROM core.account 
    cross apply ( select value from STRING_SPLIT(ts_montaguoffice, ';')) as t
    

    But it depends.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    3 deleted comments

    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.