Sql Server Ask Invalid Object Name

Muhammad Anzar 41 Reputation points
2020-12-31T19:56:24.467+00:00

Hi,

i have four tables. Three of them connected primary key and foreign key table name are(order,Order_Detail,Customer). but the fourth one is not have relation.

i want to use this table to keep company header information, To keep Data in report Header and all information change in all reports.

My query editor show the redline under the table column and table name

SELECT dbo.Customers.CompanyName AS Expr1, dbo.[Order Details].OrderID,
SELECT dbo.Customers.CompanyName AS Expr1, dbo.[Order Details].OrderID, dbo.[Order Details].ProductName, dbo.[Order Details].Discount, dbo.[Order Details].Total, dbo.[Order Details].UnitPrice,
dbo.[Order Details].DiscountAmount, dbo.[Order Details].SaleQuantity, dbo.Orders.OrderDate, dbo.Orders.DisCounter, dbo.Orders.GrandTotal,
dbo.Company_Title.*
FROM dbo.Orders INNER JOIN
dbo.[Order Details] ON dbo.Orders.OrderID = dbo.[Order Details].OrderID INNER JOIN
dbo.Customers ON dbo.Orders.CustomerID = dbo.Customers.CustomerID CROSS JOIN
dbo.Company_Title

Developer technologies | Transact-SQL
SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. EchoLiu-MSFT 14,621 Reputation points
    2021-01-01T07:57:23.207+00:00

    Hi @Muhammad Anzar ,

    Welcome to the Microsoft TSQL Q&A Forum!

    The query editor displays a red line under the table column and table name because a basic syntax error is recognized.

    ErlandSommarskog has already explained the problem of incomplete join clauses. In addition, you should accidentally put the first select statement together because the first select statement is not even a complete statement.

    By the way, I suggest you use table aliases.The use of table alias please refers to the following statement:

    SELECT c.CompanyName AS Expr1, d.OrderID,   
    d.ProductName, d.Discount, d.Total,  
    d.UnitPrice,d.DiscountAmount,   
    d.SaleQuantity, o.OrderDate, o.DisCounter,  
    o.GrandTotal,t.*  
    FROM dbo.Orders o  
    INNER JOIN dbo.[Order Details] d ON o.OrderID = d.OrderID   
    INNER JOIN dbo.Customers c ON o.CustomerID = c.CustomerID   
    CROSS JOIN dbo.Company_Title t.Order_Detail=d.Order_Detail  
    

    Since I don’t know the details of the table (columns and data), the link condition behind the cross join is my guess

    t.Order_Detail=d.Order_Detail  
    

    If you have any question, please feel free to let me know.
    If the response is helpful, please click "Accept Answer" and upvote it.

    Regards
    Echo


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.