How to Fix SQL Syntax Error in Code

Carlton Patterson 741 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
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,631 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 116.6K 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 Answers by the question author, which helps users to know the answer solved the author's problem.