The Declare SQL construct or statement is not supported.

Paul Gardiner 20 Reputation points


I recently had to reinstall my Visual Studio 2017 & SQL 2019 onto a new laptop, since then I have not been able to get a SQL Statement to work. When I run the Statement in a Query on the SQL Server it produces the result that I would expect. But when I try to use the same Statement in Visual Studio Build Query I am getting the error "The Declare SQL construct or Statement is not supported.

I have reviewed answers to similar questions posted here in this forum, but none seem to apply to my issue.

I am wondering if I have missed something when installing Visual Studio?

Here is an image of the Statement I am trying to use in VS.

User's image

Appreciate and thoughts or ideas on what I need to do to get this functioning?



Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,434 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 110K Reputation points

    Probably the Query Builder does not support this kind of scripts. It is a limitation. Maybe you can ignore the error, save the query and check it running the program. You can also check and adjust it using Management Studio or Azure Data Studio.

    For complex queries, consider Stored Procedures too.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful