SQL Syntax Error: the following errors were encountered while parsing the contents of the sql pane

483 Views Asked by At

The below view runs fine when executed, but when I try to open it in design mode, it returns a parsing error as: "The following errors were encountered while parsing the contents of the SQL pane."

Error in FROM clause: near 'VALUES'.

Error in FROM clause: near ')'.

Unable to parse query text.

SELECT
        CONCAT(q.QuotationNo, ' Rev  ', q.QuotRevNo) AS QNo
  , q.LastStatus AS Status
  , q.IsProject AS Type
  , CASE
        WHEN q.IsProject = 1
            THEN 'M'
        WHEN q.IsProject = 2
            THEN 'P'
            ELSE 'D'
    END AS [Product Type]
  , (SELECT
            MIN([Intake Date])
        FROM
            (VALUES
           (q.ORDate)
          ,(q.PIDate)
          ,(q.PODate)
          ,(q.SentTo)
          ,(q.OCDate)
          ,(q.ShipDate)
          ,(q.INVDate)
          ,(q.INVPaymentDate)) AS AllDate([Intake Date])) AS [Intake Date]
  , p.TotalOfItem   AS Sales
  , c.CompanyName   AS Customer
  , w.LastFirstName AS Contact
  , v.CompanyName   AS Vendor
FROM
    dbo.tblQuotations q
    INNER JOIN
        dbo.tblProducts p
        ON q.QuotationID = p.QuotationID
    LEFT OUTER JOIN
        dbo.tblCompany c
        ON c.CompanyID = q.CompanyID
    LEFT OUTER JOIN
        dbo.tblWContacts w
        ON q.QuotConID = w.ConID
    LEFT OUTER JOIN
        dbo.tblCompany v
        ON q.SupplierID = v.CompanyID
WHERE q.StatusCode IN (4, 5, 6, 7, 8, 9)

How to prevent the error. error message

1

There are 1 best solutions below

2
Stu On

Making an educated guess this is SQL Server, given the [delimited aliases], you could try replacing the sub-query with an apply(). Generally the best advice is to steer clear of the visual designer, it's not particularly robust.

This is untested of course but hopefully conveys the idea:

select Concat(q.QuotationNo, ' Rev  ', q.QuotRevNo) as QNo
  , q.LastStatus as Status
  , q.IsProject as Type
  , case
        when q.IsProject = 1 then 'M'
        when q.IsProject = 2 then 'P'
    else 'D' end as [Product Type]
  , d.[intake date]
  , p.TotalOfItem   as Sales
  , c.CompanyName   as Customer
  , w.LastFirstName as Contact
  , v.CompanyName   as Vendor
from dbo.tblQuotations q
join dbo.tblProducts p on q.QuotationID = p.QuotationID
left join dbo.tblCompany c on c.CompanyID = q.CompanyID
left join dbo.tblWContacts w on q.QuotConID = w.ConID
left join dbo.tblCompany v on q.SupplierID = v.CompanyID
outer apply (
    select Min(d) as [intake date]
        from (values
           (q.ORDate)
          ,(q.PIDate)
          ,(q.PODate)
          ,(q.SentTo)
          ,(q.OCDate)
          ,(q.ShipDate)
          ,(q.INVDate)
          ,(q.INVPaymentDate))v(d)
)id
where q.StatusCode in (4, 5, 6, 7, 8, 9)