What is a serious condition

KB2421014 Fix: "A fatal error has occurred in the current command" error message when you use the freeable or CONTAINSTABLE function on an indexed view in a CTE query in SQL Server 2008 or in SQL Server 2008 R2

Microsoft distributes Microsoft SQL Server 2008 or Microsoft SQL Server 2008 R2 fixes as a downloadable file. Because the fixes are cumulative, each new version contains all hotfixes and all security updates that were included in the previous version of SQL Server 2008 or SQL Server 2008 R2.

Problem Description

For example, suppose you have a named instance in Microsoft SQL Server 2008 or Microsoft SQL Server 2008 R2 that is installed on a server. When you run a common table expression (CTE) query that uses the freeable or CONTAINSTABLE function on an indexed view, the CTE query fails and an access violation exception is thrown. The following error message is also displayed:

Msg 0, Level 11, State 0, Line 0 A fatal error has occurred on the current command. The results, if any, should be discarded.

For example, the access violation exception occurs when you run the following code:

Troubleshooting

Information about the cumulative update

SQL Server 2008 Service Pack 2

The fix for this problem was first released in Cumulative Update 4 for SQL Server 2008 Service Pack 2. For more information about this cumulative update package, click the article number below to view the article in the Microsoft Knowledge Base:

2527180 Cumulative update package 4 for SQL Server 2008 Service Pack 2 Note Because the builds are cumulative, each new fix version contains all hotfixes and all security updates that were fixed in the previous version of SQL Server 2008. Microsoft recommends that you use the latest version of the fix that contains this hotfix. For more information, see the following article in the Microsoft Knowledge Base:

2402659 The SQL Server 2008 builds released after SQL Server 2008 Service Pack 2 was released Microsoft SQL Server 2008 hotfixes are created for specific SQL Server service packs. You must apply a SQL Server 2008 Service Pack 2 hotfix to an installation of SQL Server 2008 Service Pack 2. By default, any hotfix that is provided in one SQL Server service pack is included in the next SQL Server service pack.

SQL Server 2008 R2

The fix for this issue was first released in Cumulative Update 4. For more information about how to obtain this cumulative update package for SQL Server 2008 R2, click the following article number to view the article in the Microsoft Knowledge Base:

2345451 Cumulative Update Package 4 for SQL Server 2008 R2 Note Because the builds are cumulative, each new fix version contains all hotfixes and all security updates that were fixed in the previous version of SQL Server 2008 R2. We recommend that you apply the latest version of fix that contains this hotfix. For more information, see the following Microsoft Knowledge Base article:

981356 The SQL Server 2008 R2 builds released after SQL Server 2008 R2 was released

Workaround

To work around this problem, use one of the following methods:

  • Use a view, temporary table, or table variable instead of a CTE to store the intermediate results.

  • Update the query to use a derived table or subquery. This eliminates the need to use a CTE.

status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

Sources of information

For more information about using common table expressions, visit the following Microsoft website:

Using Common Table Expressions For more information about the freeable (Transact-SQL) function, see the following Microsoft website:

Freeable (Transact-SQL) For more information about the CONTAINSTABLE (Transact-SQL) function, see the following Microsoft website:

CONTAINSTABLE (Transact-SQL) For more information about creating indexed views, visit the following Microsoft website:

Creating Indexed Views For more information about the Incremental Maintenance Model for SQL Server, click the following article number to view the article in the Microsoft Knowledge Base:

935897 An incremental servicing model is available on the SQL Server team to deploy hotfixes for reported issues. For more information about the naming scheme for SQL Server updates, click the article number below to view the article in the Microsoft Knowledge Base :

822499New naming scheme for Microsoft SQL Server software update packages For more information about software update terminology, click the following article number to view the article in the Microsoft Knowledge Base:

824684 Describes the standard terminology used to describe Microsoft software updates