• I discovered this a few months back after an SQL Server Trainer told me they were only in Enterprise edition. Running nicely on my website running 2008 Express.

    When using the indexed view, you can avoid having to put with (noexpand) throughout your stored procedures/code by wrapping the indexed view in a normal view.

    The example taken from a database running on SQL 2000 Standard.

    CREATE VIEW [dbo].[vw_Country_idx] WITH SCHEMABINDING

    AS

    SELECT cg_ct_id, cg_id, c_id, cg_name, c_Name, c_shortcode

    FROM dbo.country_group

    INNER JOIN dbo.country_group_list ON cg_id = cgl_cg_id AND (cgl_Archived = 0 OR cgl_Archived IS NULL)

    INNER JOIN dbo.country ON c_id = cgl_c_id AND (c_Archived = 0 OR c_Archived IS NULL)

    WHERE (cg_Archived = 0 OR cg_Archived IS NULL)

    GO

    CREATE UNIQUE CLUSTERED INDEX [idx_vw_Country] ON [dbo].[vw_Country_idx]

    ( [c_id] ASC, [cg_ct_id] ASC)

    GO

    CREATE VIEW [dbo].[vw_Country]

    AS

    SELECT *

    FROM vw_Country_idx WITH (NOEXPAND)

    GO