vscode-sqltools icon indicating copy to clipboard operation
vscode-sqltools copied to clipboard

When trying to display a view in SQL Server 2019, get error: "Invalid usage of the option NEXT in the FETCH statement"

Open nikmartin opened this issue 2 years ago • 1 comments

When trying to fetch a view, the error in the title is displayed. Opening developer tools and looking at the response from SQL Server, here's the query that's being run:

SELECT * FROM [booked-work] ORDER BY index ASC OFFSET 0 ROWS FETCH NEXT 50 ROWS ONLY;

If I run this in Azure Dev Studio, I actually get multiple errors:

Msg 1018, Level 15, State 1, Line 1
Incorrect syntax near 'index'. If this is intended as a part of a table hint, A WITH keyword and parenthesis are now required. See SQL Server Books Online for proper syntax.
Msg 153, Level 15, State 2, Line 1
Invalid usage of the option NEXT in the FETCH statement.

To Reproduce Steps to reproduce the behavior:

  1. Go to extension 'SQL Tools'
  2. Click on Views -> View name
  3. Right click, select 'Show Table Records'
  4. See error

Expected behavior The first 50 records are displayed.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • SQLTools Version: v0.23.0
  • VSCode Version: 1.63.2]
  • OS: Windows 10
  • Driver:
    • [ ] PostgreSQL/Redshift
    • [ ] MySQL/MariaDB
    • [x] MSSQL/Azure
    • [ ] SQLite
    • [ ] Other? Which...
  • Database version: SQL Server version 15.0.2080.9

Additional context Add any other context about the problem here. I don't know why the query assumed index is a valid column to sort by, it is NOT and indexed column, it's an index into a record set for a Union statement when the view is built.

this query works fine: SELECT TOP (50) * FROM [DW].[dev_SBD].[booked-work]

this also works: SELECT * FROM [DW].[dev_SBD].[booked-work] ORDER BY (SELECT NULL) OFFSET 0 ROWS FETCH NEXT 50 ROWS ONLY;

This view has no column named 'index', BTW

nikmartin avatar Jan 06 '22 19:01 nikmartin

Given that Azure Data Studio also reports errors with that query, is your request here that SQLTools should report more details of errors? If so, this is a duplicate of #846

gjsjohnmurray avatar Sep 10 '22 15:09 gjsjohnmurray