SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


WHERE clause doesn't work in CREATE INDEX


WHERE clause doesn't work in CREATE INDEX

Author
Message
bev.kaufman
bev.kaufman
Valued Member
Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)

Group: General Forum Members
Points: 55 Visits: 48
This is in regards to Indexes, Level 7, Filters:

The command I am specifically trying to run is:

CREATE INDEX FI_SpecialOfferID
ON Sales.SalesOrderDetail (SpecialOfferID)
WHERE SpecialOfferID;

Its purpose is to screen out records where SpecialOfferID = 1, and my first thought when I first encountered it was that it was missing part of the clause. So after the first expected failure, I changed it to
CREATE INDEX FI_SpecialOfferID
ON Sales.SalesOrderDetail (SpecialOfferID)
WHERE SpecialOfferID <> 1;

But that failed with the same error:
Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'WHERE'.

I tried a couple other things, like specifying the full datapath in the WHERE clause, and nothing works. Also, I was working in Sql 2005, as directed by the series. Was it possible this syntax belongs in Sql 2008? So I tried it there and got a different error message:
Msg 4104, Level 16, State 1, Line 3
The multi-part identifier "Sales.SalesOrderDetail.SpecialOfferID" could not be bound.
Which at least makes it look like a data error and not a syntax error.
Any clues?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search