executing a sql server view vs running code in view

Scott Cabral 1 Reputation point
2020-12-10T11:51:27.983+00:00

Hi,

I have a view that was created in SQL Server. The view has about 20 joins some CTE's and a union. The code within the view runs and returns results in about 4-5 minutes. However, if I do a select * from the the view or select [column names] from the view, it doesn't finish. I let it run for 90 minutes and it never comes back with any results.

Any idea why the code within the view works but selecting from the view does not?

thanks

Developer technologies Transact-SQL
{count} votes

7 answers

Sort by: Most helpful
  1. EchoLiu-MSFT 14,621 Reputation points
    2020-12-11T06:43:32.11+00:00

    Hi @Scott Cabral ,

    I watched the whole thread,executing a sql server view vs running code in view ,should be the same.So could you provide us with the code and execution plan so that the experts can do some tests?

    Echo

    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


    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.
    Hot issues November--What can I do if my transaction log is full?
    Hot issues November--How to convert Profiler trace into a SQL Server table

    0 comments No comments

  2. Scott Cabral 1 Reputation point
    2020-12-11T18:16:28.29+00:00

    I'm having issues creating the execution plan in the database. I will need to have our DBA's take a look, but it could be a permissions issue.


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.