question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SQL Error: lack of space between the CTE's name and 'AS' keyword

See original GitHub issue

I have created a CTE and I need to get the row count letting the server to calculate the result.

There is an error on emitted SQL:

-- Wip Oracle.Managed Oracle
WITH AllowedNcCodeAS -- Should be AllowedNcCode AS 
(
        SELECT DISTINCT
                ncCode.HANDLE as NcCodeBo,
                ncCode.NC_CODE as NcCode,
                ncCode.DESCRIPTION as NcCodeDescription
        FROM
                WIPUSER.NC_CODE ncCode
                        INNER JOIN WIPUSER.NC_GROUP_MEMBER ncGroupMember ON ncCode.HANDLE = ncGroupMember.NC_CODE_OR_GROUP_GBO
        WHERE
                ((ncGroupMember.NC_GROUP_BO = 'NCGroupBO:' || ncCode.SITE || ',CATAN_AUTO' OR ncGroupMember.NC_GROUP_BO = 'NCGroupBO:' || ncCode.SITE || ',CATAN_MAN') OR ncGroupMember.NC_GROUP_BO = 'NCGroupBO:' || ncCode.SITE || ',CATAN_ALL')
)
SELECT
        COUNT(*) as Count_1
FROM
        AllowedNcCode item

I’m using the CTE as:

            var countQuery = wipCte.AllowedNcCode().Select(item => new { Count = Sql.Ext.Count().ToValue() });
            var sqlText = ((IExpressionQuery)countQuery).SqlText;

Code project: LinqToDb.Sample3.zip

Environment details

linq2db version: 3.0.0-preview.1 Database Server: Oracle Database Provider: Oracle.ManagedDataAccess.Core (3.0.0-preview.1) Operating system: Windows 10 .NET Framework:.NET Core 3.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
MaceWinducommented, Feb 6, 2020

For v3 we switched from MyGet feed to Azure Artifacts for preview versions: https://dev.azure.com/linq2db/linq2db/_packaging?_a=feed&feed=linq2db%40Local

Clicking to Connect to feed button will get you nuget feed to use with Visual studio

1reaction
sdanylivcommented, Jan 27, 2020

@filippobottega, for testing purposes turn queries logging on

DataConnection.TurnTraceSwitchOn();
DataConnection.WriteTraceLine = (s, s1) => Debug.WriteLine(s, s1);

And you can read queries in Output. Or redirect to console.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting an odd error, SQL Server query using `WITH` clause
When a CTE is used in a statement that is part of a batch, the statement before it must be followed by a...
Read more >
SQLSTATE values and common error codes
SQLSTATE values are comprised of a two-character class code value, ... SQLDA for ALL information (i.e. not enough descriptors to return the distinct...
Read more >
13.2.20 WITH (Common Table Expressions)
A common table expression (CTE) is a named temporary result set that exists within the scope of a single statement and that can...
Read more >
SQL Error when using CTE inside THEN of CASE expression
You are missing the END on your case statement. That's why you get the Incorrect syntax near the keyword 'FROM'. error. You cannot...
Read more >
Rules Reference — SQLFluff 0.6.3 documentation
Rules in SQLFluff are implemented as crawlers . These are entities which ... In this example, there is a space missing space between...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found