views:

25

answers:

2
CREATE VIEW xxxx AS
SELECT order_date, 
       DATEPART(W, order_date) AS dayID, 
       Type 
  FROM dbo.Shipment_Dates 
 WHERE (TIP = 'normal') 
OPTION (FAST 20)

This create statment causes error at hint part .. Is there a workaround for adding hint to views?

+3  A: 

Instead of specifying the hint in the definition of the view, specify the hint when using the view:

select order_date, dayID, Type
    from xxxx
    option (fast 20)
Joe Stefanelli
+3  A: 

You can't use query (OPTION) hints in a view.

A view is simply a macro that expands. The query hint would then be internal in the expansion because the view is then a subquery. And query hints are not allowed in subqueries.

Effectively, you'd have this:

select
   *
from
   (
   SELECT
     order_date, DATEPART(W, order_date) AS dayID, Type 
   FROM dbo.Shipment_Dates 
   WHERE (TIP = 'normal') 

   option (fast 20)  --not allowed
   ) WasAView

From MSDN:

Query hints can be specified only in the top-level query, not in subqueries.

gbn