Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8234835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:37:06+00:00 2026-06-07T18:37:06+00:00

I have a contracts table that is large and that we have many stored

  • 0

I have a contracts table that is large and that we have many stored procedures that query for contracts with a status of Open. Less than 10% of the contracts are open and this number is shrinking as the DB grows. I thought I could create an Indexed view of the open contracts in order to speed up some of our queries. The problem is that the status is not on the contract table and I need a subquery to retrieve the data I want. (SQL Server then does a clustered index scan on the whole table in the queries I have looked at)

Here is the condensed version of the view (I removed the 30 other columns from the contract table)

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[vw_OpenContractsIndexed]
WITH SCHEMABINDING 
AS
SELECT     c.ContractID
FROM         dbo.NMPT_Contract AS c INNER JOIN
                      dbo.NMPT_ContractStatus AS cs ON c.ContractID = cs.ContractID AND cs.ContractStatusCreated =
                          (SELECT     MAX(ContractStatusCreated) AS Expr1
                            FROM          dbo.NMPT_ContractStatus AS cs2
                            WHERE      (ContractID = c.ContractID)) INNER JOIN
                      dbo.CMSS_Status AS s ON cs.StatusID = s.StatusID
WHERE     (s.StatusCode = 'OPN')

If I try to create an index on the view (unique clustered on contractid) I get the following

Creation Failed for Index
It contains one or more disallowed constructs. (Microsoft SQL Server, Error 1936)

From what I can gather it is the Max in the subquery that is the problem??

Other than putting the status on the contracts table (where I personally think it belongs) are there any suggestions for optimising this situation. Failing that will other versions of SQL Server allow this indexed view?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:37:08+00:00Added an answer on June 7, 2026 at 6:37 pm

    From TechNet regarding Indexed Views in SS 2000:

    There are several restrictions on the syntax of the view definition.
    The view definition must not contain the following:

    COUNT(*)

    ROWSET function

    Derived table

    self-join

    DISTINCT

    STDEV, VARIANCE, AVG

    Float*, text, ntext, image columns

    Subquery

    full-text predicates (CONTAIN, FREETEXT)

    SUM on nullable expression

    MIN, MAX

    TOP

    OUTER join

    UNION

    You’re using MAX, and a subquery, both of which are not allowed.

    To get advice on how to get around this, you need to share some data and what you are trying to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large table that I'm trying to break up. For example I
I have a large table with 9 columns and 12 million rows, like this:
I have a table contacts that has a field arrayOfMembers (JSON format) and a
I have a table that represents the parameters of a contract - including their
I have a database named contacts.db with a table named TABLE_NAME that has one
I have 3 tables I need to join. The contracts table is the main
I have a rather large chunk of code that breaks sometimes, as far as
I have a method that builds and runs a Criteria query. The query does
Update: Added Schema to the bottom... I have a table of contracts: tbl_contract And
I have table customer and table contract with one-many relationship (1 customer has many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.