Re: Indexed View
- From: "John Bell" <jbellnewsposts@xxxxxxxxxxx>
- Date: Thu, 14 May 2009 09:42:42 +0100
"Michael C" <mikec@xxxxxxxxxx> wrote in message news:uN%239p5C1JHA.1420@xxxxxxxxxxxxxxxxxxxxxxx
I'm playing around with turning an existing view into an indexed view. This view has been used throughout our app so hopefully speeding up this view will improve speed in many places. I managed to get it all working except for one part. The view looks something like thisHi Michael
SELECT Blah1, Blah2, etc
FROM dbo.Table1
JOIN dbo.Table2 ON Table1.Blat1 = Table2.Blat2
WHERE this = that etc
So far so good but we have a table which simply lists rows that should be excluded, which we add to the query with a not exists
AND NOT EXISTS (SELECT * FROM dbo.ExcludeTable WHERE ExcludeTable.Blah = Table1.Blah)
The alternative is to use a left join but indexed views don't like that either. Is there anything I can do? I know I can change the data structure (to, say have an exclude bit in table1) but I didn't make these tables and changing them would require a lot of pain. Is there anything I can do without changing the tables?
Thanks again,
Michael
You can't have sub-queries, EXCEPT , UNION or INTERSECT in an indexed view so it will not be possible to do what you want in a single view. The error message you should have got, does suggest the alternative of creating a separate indexed view for each part, i.e make the exclusion outside the view.
John
.
- Follow-Ups:
- Re: Indexed View
- From: Michael C
- Re: Indexed View
- References:
- Indexed View
- From: Michael C
- Indexed View
- Prev by Date: Re: Calling a function on a linked server from a stored procedure
- Next by Date: Re: Join and Replace with SQl 2005?
- Previous by thread: Indexed View
- Next by thread: Re: Indexed View
- Index(es):
Relevant Pages
|