Query takes long time to run

SQLIsGood-7036 176 Reputation points
2020-08-27T14:38:34.403+00:00

SQL Server: 2014

Problem: I am running a query that joins 3 views and produces results. Query takes over 8 minutes to run, but it runs without an error and produces correct output.

Can you please take a look at my query and tell me why it takes 8 mins for it to run? Server has no shortage of resources, all the other tasks are running without a problem.

Thank you.

select DISTINCT
n1.[Bill Account Number],
n1.[Service Account Number],
n1.[Service Customer Name],
n1.[Service Street Name],--Service address
n1.[Service Street Number],
n1.[Apartment Number],
n1.[Telephone Number],
n1.[Company Name],
n1.[Core Service Type],
n1.[Service Status],
n1.[Service Type],

n2.[USEC Code],
n2.[Rate Table],
n2.[USEC Desc],
n2.[Recurring Amount],
n2.[USEC Quantity],

n3.[Service Account Number],
n3.[Company Name] as COMPANY

FROM [dbo].[View1] AS n1

INNER JOIN

[dbo].[View2] AS n2

ON

n1.[Bill Account Number]=n2.[Bill Account Number]

INNER JOIN

[dbo].[View3] AS n3

ON
n2.[Service Account Number]=n3.[Service Account Number];

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,961 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,652 questions
0 comments No comments
{count} votes

Accepted answer
  1. Williams, Jeffrey A 481 Reputation points
    2020-08-27T16:23:27.27+00:00

    We need to see the code in each view - but just with this the only thing I can say is that it doesn't have a WHERE clause and you are using DISTINCT.

    It would also help if you could provide the execution plan - which would help identify if there are missing indexes or statistics.

    0 comments No comments

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.