A SQL2005 query worked before but not now.

Kay_Lee 101 Reputation points
2024-09-27T08:50:40.3566667+00:00

select name, EDI_code, perdose, perday, howlongday, count(*) AS frequencies from prescriptions_pharmacy group by name, EDI_code, perdose, perday, howlongday

When I execute above query in Server Management Studio Express, Incorrect syntax near '' error is shown. between '', there is nothing.

I'm confused the SQL Server was 2005 or 2014. At this time, I have to use SQL2005 Server.

Please kindly advise me.

Thank you !

Edited-

2 Screenshots are attached, And the Korean language '' 근처의 구문이 잘못되었습니다 is incorrect syntax near ''

According to my records, this query succeeded in March, 2023 for the last time.

The Sql Server Management Studio Express version was 2005, and I change it to 2014 but as you might expect well, change the version of Management Studio didn't solve the problem.

In case of normal situation, normal syntax, of course I try my best to find the answer on my own, but for this case, it seems really strange and so I ask here.

sql query_strange error_1

sql query_strange error_2

SQL Server | Other
{count} votes

4 answers

Sort by: Most helpful
  1. Olaf Helper 47,586 Reputation points
    2024-09-27T08:55:00.18+00:00

    I'm confused the SQL Server was 2005 or 2014

    Very different version numbers, but both have one thing in common: Out-of-support!

    There is no syntax failure in your SQL, there must be something else in your Query Window.

    0 comments No comments

  2. LiHongMSFT-4306 31,616 Reputation points
    2024-09-27T09:04:49.72+00:00

    Hi @Kay_Lee

    It seems to me that there is no syntax error.

    Try to select the whole query with the mouse and then click the Execute button.

    Or open another query widow and try again?

    Best regards,

    Cosmog


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

  3. Erland Sommarskog 129.6K Reputation points MVP Volunteer Moderator
    2024-09-30T11:22:08.09+00:00

    The reason is like to be due to that one of the spaces in the string is a hard space, Unicode character 160. Up to SQL 2008, SQL Server did not recognise the hard space as a white-space character, and would yield a syntax error if it encountered one.

    Try deleting all spaces and re-inserting them.


  4. Kay_Lee 101 Reputation points
    2024-10-01T08:05:24.4333333+00:00

    I think this is some bug(?) of SQL Server 2005 (20 years old..)

    I tried a basic way like 'select xxx from table' (the minimum structure) and it worked fine.

    And I added the rest branches like where, group by, having and it also worked.

    0 comments No comments

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.